The SAS Output Delivery System and reporting techniques

PROC REPORT — How to control order of ACROSS levels

Reply
Trusted Advisor
Posts: 1,783

PROC REPORT — How to control order of ACROSS levels

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?

SAS Super FREQ
Posts: 8,815

Re: PROC REPORT — How to control order of ACROSS levels

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:

order_data_report.png

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;

Trusted Advisor
Posts: 1,783

Re: PROC REPORT — How to control order of ACROSS levels

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!

SAS Super FREQ
Posts: 8,815

Re: PROC REPORT — How to control order of ACROSS levels

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

Super User
Posts: 9,856

Re: PROC REPORT — How to control order of ACROSS levels

Another workaround is adding BLANKS before its value .

SAS Super FREQ
Posts: 8,815

Re: PROC REPORT — How to control order of ACROSS levels

Hi:

  The "blank" technique doesn't always work the same in ALL destinations.

cynthia

Ask a Question
Discussion stats
  • 5 replies
  • 575 views
  • 0 likes
  • 3 in conversation