The question is:
The answer is:
data work.cleandata36;
set cert.input36;
if upcase(group) in ('A','B');
run;
I don't understand since there is no 'then do' or anything after if upcase(group)in ('A', 'B'). Could you explain why? Thanks.
The IF without a then is called a subsetting IF. It means "only keep records if the condition is true".
BTW that is not actually a correct answer. There is nothing that makes the values upper case to keep.
If the values are lower case they will still be so in the output.
data junk; input group $; datalines; a b c d e g junk ; data want; set junk; if upcase(group) in ('A','B'); run;
Note that group = "a" and "b" are in the output.
there should be a statement like:
group = upcase(group);
if the values in the output set are supposed to be upper case.
This is called the "subsetting IF statement". It does not use a THEN clause. Think of it like a filter: Only observations that satisfy the IF condition are output to the data set.
@dooheekim01 wrote:
The question is:
- create a temporary data set, cleandata36.
- In this data set, convert all group values to upper case.
- Then keep only observations with group equal to 'A' or 'B'.
The answer is:
data work.cleandata36;
set cert.input36;
if upcase(group) in ('A','B');
run;
I don't understand since there is no 'then do' or anything after if upcase(group)in ('A', 'B'). Could you explain why? Thanks.
The code would work, except that it does not do this part of the question: "convert all group values to upper case", so the output data set could contain lowercase 'a' or lowercase 'b'. You need one more statement to make all the values uppercase.
The IF without a then is called a subsetting IF. It means "only keep records if the condition is true".
BTW that is not actually a correct answer. There is nothing that makes the values upper case to keep.
If the values are lower case they will still be so in the output.
data junk; input group $; datalines; a b c d e g junk ; data want; set junk; if upcase(group) in ('A','B'); run;
Note that group = "a" and "b" are in the output.
there should be a statement like:
group = upcase(group);
if the values in the output set are supposed to be upper case.
Thank you so much!
I have another question for the upcase function and the in operator.
I used:
Upcase(group) in (upcase('a'), upcase('b'));
But it does NOT work, showing error message.
Please help.
Thanks
As stated in the documentation for the IN operator, the list of values on the right side must be CONSTANT values, not expressions.
Thanks, I see.
the similar omissions can be found in the following cases;
proc sort data = scoredata_p;
by stu_id;
run;
proc sort data = scoredata;
by stu_id;
run;
data MMA;
merge scoredata_p(in = A) scoredata (in = B);
by stu_id;
if A and B;
run;
in selected variable merge (stu_id), you can omit A=1 and B=1 in 'if' statement.
why it gives different answer if i use where statement instead of if statement.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.