02-15-2018 12:33 PM
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?
02-15-2018 12:41 PM
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;
02-15-2018 01:26 PM - edited 02-15-2018 01:33 PM
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;