Hi,
suppose I have the variable diff and 5 other variables (among many others) a,b,c,d,e.
Whenever the diff = '' I want also the other 5 variabels also be =''.
I did the following code:
data have;
set have;
array variables[5]
a b c d e;
if diff = '' then
do i = 1 to 5
variables[i]= '';
end;
drop i ;
run;
But get errors... I guess that the logic of my syntax isn't correct, although I tried to do some modifications of the code and still get errors. Could you please help me?
Thank you!
data have;
set have;
array variables[5] a b c d e;
if diff ='' then call missing(of variables[*]);
run;
I think I got it: I should have put the if statement inside the do statament:
data have;
set have;
array variables[5]
a b c d e;
do i = 1 to 5;
if diff ='' then variables[i] = '';
end;
drop i;
run;
But if there is a better way I will be very happy to learn!!!
CALL MISSING()
This code doesn't care if diff and variables are character or numeric.
if missing(diff) then call missing(of variables(*));
data have;
set have;
array variables[5] a b c d e;
if diff ='' then call missing(of variables[*]);
run;
While you have some valid suggestions here, your original problem was a missing semicolon:
1 to 5 ;
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!
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.