06-16-2015 02:30 PM
In PROC REPORT, I have a variable which is defined as an ACROSS variable. I would like to control the order of the values of this variable that appear in PROC REPORT left to right in the output.
So, for example, if I used
define defect_level/across "Defect Level";
and this variable defect_level had three levels "Poor" "Average" "Excellent", I'd like them to appear left to right in that order. But apparently, the default mode of operation places these in alphabetical order, which I don't want.
How do I get these variable levels to appear in the order I want in the PROC REPORT output?
06-16-2015 02:54 PM
Usually, assuming your data are in the correct order you want, you can specify ORDER=DATA on the DEFINE statement:
define defect_level / across order=data;
for example, this output was produced with the program shown below -- note the order of the ACROSS items is not alpha order and not descending order either:
***Here is the program;
input type $ row $ val;
XXX AAA 10
XXX AAA 20
XXX BBB 30
XXX BBB 40
XXX CCC 15
HHH AAA 20
HHH BBB 20
HHH CCC 20
RRR AAA 20
RRR AAA 20
RRR BBB 40
RRR CCC 50
ods html file='c:\temp\report_order.html';
proc report data=fakedata nowd;
column row type,val;
define row / group;
define type / across order=data;
define val / sum;
ods html close;
06-16-2015 03:07 PM
Thank you, Cynthia. I knew it was something simple, and I am surprised that I couldn't find that option myself ... but that's what the forum is for!
06-16-2015 03:20 PM
Look here for the DEFINE statement documentation: Base SAS(R) 9.4 Procedures Guide, Third Edition ORDER= is a link that will take you directly to the description of the option. There are some other procedures that have an ORDER= option and they all generally work the same way.