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?