You original data is in categorical form. That is good!
You are asking for a transformation that changes data (month part of date) into meta data (month name as column). This means down the road you will be dealing with arrays or variable name lists.
I would recommend keeping your data in categorical form. Categorical form means you can use CLASS
and BY
statements for efficient processing. Use Proc TABULATE
to arrange your data items for output or delivery consumption (such as ODS EXCEL).
data have;
attrib date informat=date9. format=date9.;
input date value @@;
date_again = date;
datalines;
1Sep11 389.00 1Oct11 491.00 1Nov11 370.00 1Dec11 335.00
2Sep11 423.00 2Oct11 478.00 2Nov11 407.00 2Dec11 442.00
3Sep11 482.00 3Oct11 300.00 3Nov11 303.00 3Dec11 372.00
run;
proc tabulate data=have;
class date date_again;
var value;
format date monname.;
format date_again day.;
table date_again='', date=''*value=''*max='' / nocellmerge;
run;
ODS LISTING output
-------------------------------------------------------------
| | September | October | November | December |
|-------+------------+------------+------------+------------|
|1 | 389.00| 491.00| 370.00| 335.00|
|-------+------------+------------+------------+------------|
|2 | 423.00| 478.00| 407.00| 442.00|
|-------+------------+------------+------------+------------|
|3 | 482.00| 300.00| 303.00| 372.00|
-------------------------------------------------------------
If you feel you must transpose the data, split out the day and month for use as by
and id
data have2(keep=day month value);
attrib date informat=date9. format=date9.;
input date value @@;
day = day(date);
month = put(date,monname3.);
datalines;
1Sep11 389.00 1Oct11 491.00 1Nov11 370.00 1Dec11 335.00
2Sep11 423.00 2Oct11 478.00 2Nov11 407.00 2Dec11 442.00
3Sep11 482.00 3Oct11 300.00 3Nov11 303.00 3Dec11 372.00
run;
proc transpose data=have2 out=want2(drop=_name_);
by day;
var value;
id month;
run;
You are also going to run into problems when overall date range exceeds one year, or if the raw data rows are not day in month grouped or are disordered.