BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Barkat
Pyrite | Level 9

In my dataset I have two variables, Test and Standard. Both have two options, Pos and Neg. When I run the following SAS code then the output table shows Pos and Neg in reverse order, so results are reversed. How can I fix it.

 

Proc freq data=have;

tables Test*Standard/senspec;

run;

 

I get the following table as output

  Neg Pos
Neg    
Pos  

 

 

I want the following table as output

  Pos Neg
Pos    
Neg    
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

N comes before P alphabetically. So that is the default order you will get from the output of Proc Freq.

 

If the order is that important try:

Proc sort data=have;
   by descending test descending standard;
run;

Proc freq data=have order=data;
   tables test*standard;
run;

The sort places Pos before Neg and the Proc Freq option order=data tells SAS to display data in the order encountered in the data set instead of the default internal order.

 

Another approach is to create numeric variables with the value 1= first to display, 2= second to display and so on. Then create a custom format to display the desired text. Use that format in Proc Freq. By default the order would be the internal 1, 2, 3 (etc) but the formatted value will appear.

View solution in original post

1 REPLY 1
ballardw
Super User

N comes before P alphabetically. So that is the default order you will get from the output of Proc Freq.

 

If the order is that important try:

Proc sort data=have;
   by descending test descending standard;
run;

Proc freq data=have order=data;
   tables test*standard;
run;

The sort places Pos before Neg and the Proc Freq option order=data tells SAS to display data in the order encountered in the data set instead of the default internal order.

 

Another approach is to create numeric variables with the value 1= first to display, 2= second to display and so on. Then create a custom format to display the desired text. Use that format in Proc Freq. By default the order would be the internal 1, 2, 3 (etc) but the formatted value will appear.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 289 views
  • 1 like
  • 2 in conversation