Please can someone tell me how to save the unique values that are shown from a proc freq of a variable in the 'Results' tab and save them as a new dataset with just that one variable and all of the values? The proc freq of my variable shows that there are over 100 different values.
You use the OUT= option of the TABLES statement in PROC FREQ.
... so that I am left with just the values of the variable
You can use the NLEVELS option in the PROC FREQ statement if you just want the levels and not the count or percent. And ODS output to get it into a data set.
@Justin9 wrote:
Thanks! Is there a way to exclude the 'count' and 'percent' columns in the output (from the out= option, not the proc freq), so that I am left with just the values of the variable?
Yes, you can use data set options in the output such as DROP/KEEP.
tables sex / out=want (drop = percent);
@Justin9 wrote:
Is there also a way to exclude the missing row in the output?
Yes, you can use data set options in the output such as WHERE.
tables age / out=want (where = not missing(age));
Putting it all together:
data class;
set sashelp.class;
if age=14 then call missing(age);
run;
proc freq data=class noprint;
tables age / out=want (where=(not missing(age))
drop = percent ) ;
run;
proc print data=want;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.