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?
Hi:
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:
cynthia
***Here is the program;
data fakedata;
infile datalines;
input type $ row $ val;
return;
datalines;
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
;
run;
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;
run;
ods html close;
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!
Hi:
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.
cynthia
Another workaround is adding BLANKS before its value .
Hi:
The "blank" technique doesn't always work the same in ALL destinations.
cynthia
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: