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.
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.