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?

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 667 views
  • 0 likes
  • 4 in conversation