BookmarkSubscribeRSS Feed
dooheekim01
Obsidian | Level 7

Would you mind letting me know the difference of those two codes? I really don't know functionally what the difference is / what makes the difference of the 2 observations.

 

1) 

data cleandata36;
set cert.input36;
if upcase(Group) in ('A', 'B') then do;
end;
run;

proc contents data=cleandata36;
run;

 

2) 

data cleandata36;
set cert.input36;
if upcase(Group) in ('A', 'B');
run;

proc contents data=cleandata36;
run;

 

"Then do" is one difference. So, the only one difference of two codes is 'observation'

1) 

Observations

5000

2) 

Observations

4992

 

Thank you. 

3 REPLIES 3
Reeza
Super User
The second IF is known as a SUBSETTING IF, where it filters the records to limited records that meet the condition.

The first IF, will execute conditional logic between the DO/END statement but you have nothing so the first IF doesn't do anything. If you added a DELETE in between the DO;/END; it will then be the same.

if upcase(Group) in ('A', 'B') then do;
DELETE;
end;

In general, you use IF/THEN/DO when you want to do more than one thing in the step. If you want to filter or only do one thing then you can stick with IF/THEN.

Ksharp
Super User
if upcase(Group) in ('A', 'B');
stands for
if upcase(Group) in ('A', 'B') then output;
Kurt_Bremser
Super User

The IF Statement: Subsetting causes the data step (if the condition does not resolve to true) to immediately return to the top, skipping any remaining statements and starting the next iteration. This also means that the implicit OUTPUT at the end of the data step (if no explicit OUTPUT was coded) is not performed.

The "normal" IF does not do this, and therefore all observations in your example are kept.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1302 views
  • 2 likes
  • 4 in conversation