BookmarkSubscribeRSS Feed
Koke
Fluorite | Level 6

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
1 REPLY 1
Ron_MacroMaven
Lapis Lazuli | Level 10

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

 

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
  • 1 reply
  • 3053 views
  • 1 like
  • 2 in conversation