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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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