In a data step, if one of a set of variables is a certain value and others are missing, how do we tell SAS to fill in other variables with a certain value?
Above is the data set I have. If one of DEMA4A to DEMA4F is Y but others are missing, I want to fill in these missings with "N"
If one or more values of DEMA4A to DEMA4F are U, I don't want to fill in any missing values.
How do I write this code?
Use WHICHC to evaluate your condition:
if whichc(‘Y’, of DEMA4A—DEMA4f) then do;
your assignment statements;
end;
data want;
set have;
array t(*)DEMA4A--DEMA4F;
x1=whichc('Y', of t[*]);
if x1>0 then do;
do _n_=1 to dim(t);
if _n_ ne x1 then t(_n_)='N';
end;
run;
one way to do this and is similar to @novinosrin code and I just added one more condition
data want;
set have;
array name(*) $ DEMA4A--DEMA4F;
if whichc('Y', of name[*]) and whichc('U', of name[*]) = 0 then
do i = 1 to dim(name);
if name[i] =' ' then name[i] = 'N';
else name[i] =name[i];
end;
drop i;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.