Is it possible to create a macro variable that is set to the frequency variable produced by proc freq? I'm trying to create a variable that will equal the number of times each last name appears in a data set. For example, Smithe may appear 3 times while Jackson appears only 2 times. I want to capture that value and use it.
0
votes
1 Answers
3
votes
You can either use call symput in a following data step (after outputting the proc freq to a dataset with /out= and/or using ods output), or you can avoid the proc freq and do the frequency with proc sql via select into, which will create a macro variable.
proc sql;
select sex, count(1)
into :sex separated by ' ',
:count separated by ' '
from sashelp.class
group by sex;
quit;
This makes something approximating a pair of macro variable arrays (one with the values one with the counts). If you want to use the name (or whatever) as the macro variable name, use the first option (follow-on datastep with call symput) as that lets you name the macro variable.