I have a panel data, which I would like to display by using PROC REPORT.
proc report data=sashelp.stocks out=lat(drop=_break_) nowd; where year(date)>= 2005; column Stock Date, (AdjClose Volume); define Stock / group left; define Date/ across order= internal; COMPUTE AdjClose ; CALL DEFINE(_COL_, "style", "STYLE=[BACKGROUND=MISTYROSE]"); ENDCOMP; COMPUTE Volume; CALL DEFINE(_COL_, "style", "STYLE=[BACKGROUND=lightblue]"); ENDCOMP; quit;
I was wondering if I can make two "rows" (one for AdjClose and the other for Volume) for each group (i.e., IBM, Intel, Microsoft).
What I would like to have:
03JAN05 01FEB05 ......
While this is possible, it requires you to re-arrange the data set (extra work) and then you'd also have to provide different formats for the different rows, as AdjClose and Volume would have to formatted differently (extra work).
Is it worth the extra work??
Step 1: rearrange the data so that the two columns of interest are now one column with two rows.
data stocks; set sashelp.stocks; length type $ 8; type='AdjClose'; value=adjclose; output; type='Volume'; value=volume; output; run;
Step 2: Execute PROC REPORT with the new "one column with two variables" as a GROUP variable
proc report data=stocks(where=(year(date)>= 2005)); columns stock type date,value; define stock/group; define type/group; define date/across; define value/sum; run;
Step 3: Change the formats on the rows if desired, see this explanation by @Cynthia_sas here: https://communities.sas.com/t5/ODS-and-Base-Reporting/PROC-REPORT-different-formats-for-different-ro...
Tabulate will do this pretty easily:
proc tabulate data=sashelp.stocks; where year(date)>= 2005; class stock date; var AdjClose volume; tables stock*( AdjClose*max=''*f=dollar8.2 volume*max=''*f=comma14.), date /row=float ; run;
A concern though is tabulate must report a statistic for the body of the table as it has no "list" behavior except for the row and column headings. So if you have a single value per group crossing (stock and date), such as in this case, you could use any of Mean, Max, or Min. The =' ' is to suppress a column or row label, the format has to be applied to the Statistic not the variable. The row=float table option suppresses a blank column you would get for the missing Max label. Style elements for background could immediately follow the statistic to display as desired (but before the *f= which sets the specific format for the cells).
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.