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
SAS Super FREQ

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
SAS Super FREQ

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
SAS Super FREQ

Hi:

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

cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 3831 views
  • 0 likes
  • 3 in conversation