Hello, I have a large dataset that contains multiple categorical variables.
For each variable, entry options are:
Yes / No / Unknown / Missing
I need to transform each variable into a binary variable: Yes vs. No/Unknown/Missing.
Two questions:
1) Is there a way to do this directly in proc freq or is it necessary to create a large number of new variables (e.g. apple_bin, orange_bin) in a data step first?
2) If a data step is necessary, is there a way to generate all of these new variables using a do loop? Each variable has a different name (e.g., apples, oranges, bananas) so I can't use a range (var1-var3).
Thanks very much,
Emily
Should No/Unknown/Missing all transform to 0 ?
It depends on your ultimate objective. If you just want to run PROC FREQ, that can be done easily:
proc format;
value $yes 'Yes' = '1' 'No', 'Missing', 'Unknown' = '0';
run;
proc freq data=have;
tables _character_;
format _character_ $yes.;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.