SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

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?

 

1 REPLY 1
unison
Lapis Lazuli | Level 10

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;
-unison

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 684 views
  • 0 likes
  • 2 in conversation