data have;
infile datalines;
input setup_date date9. Type $ cnt;
return;
datalines;
1jun2019 Central 5
1jun2019 West 6
12jul2019 East 6
14aug2019 West 2
15aug2019 West 1
20aug2019 East 1
;run;
data have2;
set have;
monthsum = month(setup_date);/*returns numeric*/
Month1 = put(setup_date,monyy5.);/*change to character*/
format setup_date date9.;
run;
proc report data=have2 wrap style(column)={just=center};
column Type monthsum /*MONTH1*/ setup_date cnt ;
define Type / group style (column)=[cellwidth=100pt] "EXC TYPE";
define monthsum /group noprint order = internal;
/*define MONTH1 /across style(column)=[cellwidth=100pt] "MONTH";*/
define setup_date / across order = internal format = monyy5. "Month";
define cnt / sum "Row Total" style(column)=[cellwidth=90pt];
rbreak after / summarize style (summary)= Header;
compute after;
Type = 'Grand Total';
endcomp;
run;
The code works without issue however is there a way to sort descending in proc report by the cnt? Currently I am defining cnt with a sum. Can it be re-defined in descending order?
You can sort beforehand:
proc sort data=have2; by type descending cnt; run;
and then use order=data
define cnt / sum "Row Total" style(column)=[cellwidth=90pt] order=data;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.