DATA Step, Macro, Functions and more

Proc freq ascending order

Reply
Occasional Contributor
Posts: 17

Proc freq ascending order

Hello all,

I want the table, which shows frequency of observation in ascending order

Here is my output

  STATE1 Frequency NJ NY PA
1
1
1
  STATE2 Frequency Frequency Missing = 1 NJ NY
1
1
  STATE3 Frequency Frequency Missing = 1 CA PA
1
1
  STATE4 Frequency Frequency Missing = 2 TX
1
  STATE5 Frequency Frequency Missing = 2 GA
1
 
 I want the table that has the frequency 1 come first and then 2 and 3.
here is my code
DATA STATE (drop = i);
INFORMAT STATE1-STATE5 $2.;
INPUT ID STATE1-STATE5;
array vars[*] _character_;
do i=1 to dim(vars);
if vars[i]= 'XX' then vars[i]= ' ';
end;
DATALINES;
1 NY NJ PA TX GA
2 NJ NY CA XX XX
3 PA XX XX XX XX
;
proc
print data=state;

proc
freq data=state;
table STATE1-STATE5/ nocum nopercent;
run;

 here is my log

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
61
62 DATA STATE (drop = i);
63 INFORMAT STATE1-STATE5 $2.;
64 INPUT ID STATE1-STATE5;
65 array vars[*] _character_;
66 do i=1 to dim(vars);
67 if vars[i]= 'XX' then vars[i]= ' ';
68 end;
69 DATALINES;
 
NOTE: The data set WORK.STATE has 3 observations and 6 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.02 seconds
 
73 ;
 
74 proc
75 print data=state;
76
 
NOTE: There were 3 observations read from the data set WORK.STATE.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.21 seconds
cpu time 0.22 seconds
 
77 proc
78 freq data=state;
 
79 table STATE1-STATE5/ nocum nopercent;
80 run;
 
NOTE: There were 3 observations read from the data set WORK.STATE.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.29 seconds
cpu time 0.27 seconds
 
 
81
82 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
95
 
thank you guys
Regular Contributor
Posts: 227

Re: Proc freq ascending order

save the output and sort it

 

PROC freq data = &syslast;

          tables ... /noprint

          out = list_values;

run;

PROC sort data = &syslast;

          by count;

PROC print;

run;

 

Ron Fehd out-data maven

 

Ask a Question
Discussion stats
  • 1 reply
  • 74 views
  • 0 likes
  • 2 in conversation