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 ;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.