BookmarkSubscribeRSS Feed
Bluekeys49
Obsidian | Level 7

I have 50 survey variables, named AB1, AB2, AB3,...,AB50.  Most of these variables contain a survey response, either answer choice A, B, or C.  In some cases, there is no response in which the field has NULL entered in the cell.  How do I change all of these NULL responses to a 0 without doing an if/then statement for each individual variable?  Thanks for any help!

5 REPLIES 5
ketpt42
Quartz | Level 8
data want;
set have;
array abvar{*} $ AB1-AB50;
do i = 1 to dim(abvar);
if missing(abvar(i)) then abvar(i) = '0';
end;
drop i;
run;
sustagens
Pyrite | Level 9
If variables are character, zero should be quoted
Patrick
Opal | Level 21

If you need this only for display purposes then you can also use:

options missing='0';

Only works for numerical variables.

 

Bluekeys49
Obsidian | Level 7
I neglected to mention that this survey is being imported in from Excel. The questions that were skipped (no response) were automatically populated with the word NULL when imported into SAS for analysis. So, wanting to change all occurrences of this text NULL value globally to 0 in any response field it exists.
sustagens
Pyrite | Level 9

Change @ketpt42's code above to

if abvar(i)='NULL' then abvar(i) = '0';

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
  • 5 replies
  • 1786 views
  • 1 like
  • 4 in conversation