- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
As stated in the documentation for the IN operator, the list of values on the right side must be CONSTANT values, not expressions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, I see.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
why it gives different answer if i use where statement instead of if statement.