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;
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.
@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.
So the variable GROUP will always have the value '2'.
Can you explain why?
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!
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.