Help using Base SAS procedures

PROC FREQ -- change the order of the output

Accepted Solution Solved
Reply
Super Contributor
Posts: 279
Accepted Solution

PROC FREQ -- change the order of the output

How can I change the order of the output so that grade17 appears in descending order?

 

SAS Output

grade17 exitcode grade16 exit16 Frequency Percent Cumulative
Frequency
Cumulative
Percent
0   .   574 5.72 574 5.72
0   0   213 2.12 787 7.85
0   0 NS 1 0.01 788 7.86
1   .   44 0.44 832 8.30
1   0   731 7.29 1563 15.58
1   0 GC 3 0.03 1566 15.61
1   0 NS 1 0.01 1567 15.62
1   0 W22 10 0.10 1577 15.72
1   0 W25 1 0.01 1578 15.73
1   1   12 0.12 1590 15.85
2   .   40 0.40 1630 16.25

Accepted Solutions
Solution
‎11-18-2016 10:22 AM
Super User
Posts: 11,343

Re: PROC FREQ -- change the order of the output

Easiest may be to send the data to an output data set and sort that.

 

proc freq noprint ;
table grade17*exitcode*grade16*exit16/list missing out=temp ;
run;

 

proc sort data=temp;

   by descending grade17;

run;

 

proc print data=temp;

run;

View solution in original post


All Replies
Super User
Posts: 19,768

Re: PROC FREQ -- change the order of the output

Include the code you're using please. 

 

Have you tried order= option?

Super Contributor
Posts: 279

Re: PROC FREQ -- change the order of the output

proc freq;
table grade17*exitcode*grade16*exit16/list missing;
run;

Solution
‎11-18-2016 10:22 AM
Super User
Posts: 11,343

Re: PROC FREQ -- change the order of the output

Easiest may be to send the data to an output data set and sort that.

 

proc freq noprint ;
table grade17*exitcode*grade16*exit16/list missing out=temp ;
run;

 

proc sort data=temp;

   by descending grade17;

run;

 

proc print data=temp;

run;

New Contributor
Posts: 3

Re: PROC FREQ -- change the order of the output

You need to sort the data in descending order by grade17.  Then, in the proc freq, use the order=data option.

 

proc sort data=filename;

by descending grade17;

run;

 

proc freq data=filename order=data;

table grade17*exitcode*grade16*exit16;

run;

SAS Super FREQ
Posts: 3,752

Re: PROC FREQ -- change the order of the output

Posted in reply to BigFluffyTail

In this case you only needed a sort on one variable. If you ever need to sort by two variables, see the article "How to order categories in a two-way table with PROC FREQ."

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 391 views
  • 1 like
  • 5 in conversation