I have 30 survey variables, named AB_1, AB_2, AB,_3,...,AB_30. Most of these variables contain a survey response, either answer choice A, B, or C. In some cases, the responses are blank. How do I change all blank responses to a code of 5? I know there has to be as shorter way rather than me coding out
if AB_1 = ' ' then AB_1 = '5';
if AB_2 = ' ' then AB_2 = '5';
if AB_3 = ' ' then AB_3 = '5';
.
.
if AB_30 = ' ' then AB_30 = '5';
Thanks for any help!
This is a job for an ARRAY.
data want;
set have;
array ar ar_1-ar_30;
do i=1 to dim(ar);
if ar(i)=' ' then ar(i)='5';
end;
drop i;
run;
Although, I do feel the need to ask — why do you need to do this? What can you do with a '5' that you can't do with a ' '?
Thank you very much. It worked. Not sure if I will keep blanks or recode to another value, so I just used 5 as an example.
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.
Ready to level-up your skills? Choose your own adventure.