BookmarkSubscribeRSS Feed
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
5 REPLIES 5
Cynthia_sas
Diamond | Level 26

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;

PaigeMiller
Diamond | Level 26

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!

--
Paige Miller
Cynthia_sas
Diamond | Level 26

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

Ksharp
Super User

Another workaround is adding BLANKS before its value .

Cynthia_sas
Diamond | Level 26

Hi:

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

cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 5589 views
  • 0 likes
  • 3 in conversation