BookmarkSubscribeRSS Feed
Bluekeys49
Obsidian | Level 7

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!

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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 ' '?

--
Paige Miller
Bluekeys49
Obsidian | Level 7

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 630 views
  • 2 likes
  • 2 in conversation