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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.