Contributor
Posts: 25

# If one of a set of variables is a certain value and others are missing -

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?

Super User
Posts: 23,980

## Re: If one of a set of variables is a certain value and others are missing -

Use WHICHC to evaluate your condition:

if whichc(‘Y’, of DEMA4A—DEMA4f) then do;

end;

Super User
Posts: 2,049

## Re: If one of a set of variables is a certain value and others are missing -

``````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;``````
PROC Star
Posts: 549

## Re: If one of a set of variables is a certain value and others are missing -

[ Edited ]

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;``````

Discussion stats
• 3 replies
• 119 views
• 3 likes
• 4 in conversation