BookmarkSubscribeRSS Feed
EmilyAV
Calcite | Level 5

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

 

4 REPLIES 4
Reeza
Super User
FYI - most procs in SAS don't require this if they support the CLASS statement which will do it as part of the PROC. If you're using PROC LOGISTIC, PHREG for example it will do this automatically, no need to recode them yourself manually.
PeterClemmensen
Tourmaline | Level 20

Should No/Unknown/Missing all transform to 0 ?

Astounding
PROC Star

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;

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 3004 views
  • 6 likes
  • 4 in conversation