BookmarkSubscribeRSS Feed
Guptashwe
Calcite | Level 5

What would be the output value for group when the age is not 14? and why

 

data test;
set sashelp.class;
if age = 14 and sex = 'M' then do;
y =1;
group = '2';
end;
else do;
y =2;
group = '22';
end;
run;

 

 

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

So the logic is, if age=14 and sex=m do first set, otherwise do second set.  If age is not 14, then the first part of the if is false, and so the if statement cannot be true, therefore operation passes to the else do section.

PaigeMiller
Diamond | Level 26

@Guptashwe wrote:

What would be the output value for group when the age is not 14? and why

 

data test;
set sashelp.class;
if age = 14 and sex = 'M' then do;
y =1;
group = '2';
end;
else do;
y =2;
group = '22';
end;
run;

 

 


You can run the code yourself and find out what the output value for group is.

 

Why is that value assigned? Anyone who is 14 years old AND sex='M' gets group='2'. Everyone else is processed through the ELSE DO; block of code.

--
Paige Miller
Tom
Super User Tom
Super User

So the variable GROUP will always have the value '2'.

 

Can you explain why?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1014 views
  • 0 likes
  • 4 in conversation