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!
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;
If you need this only for display purposes then you can also use:
options missing='0';
Only works for numerical variables.
Change @ketpt42's code above to
if abvar(i)='NULL' then abvar(i) = '0';
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.