BookmarkSubscribeRSS Feed
gsk
Obsidian | Level 7 gsk
Obsidian | Level 7

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? 

 

dataset.JPG

 

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? 

3 REPLIES 3
Reeza
Super User

Use WHICHC to evaluate your condition:

 

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

 

your assignment statements;

 

end;

novinosrin
Tourmaline | Level 20
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;
kiranv_
Rhodochrosite | Level 12

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;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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