Hi,
In which instance , can use WHERE or IF, below two code give me different results?
Scenario is -Remove observations with RestHR values that are greater than or equal to 70
data work.stress1;
set cert.stress;
if RestHR ge 70 then delete;
TotalTime= (TimeMin*60 )+ TimeSec;
if TotalTime<600 then delete;
run;
data work.stress1;
set cert.stress;
where RestHR <= 70;
TotalTime= (TimeMin*60 )+ TimeSec;
if TotalTime<600 then delete;
run;
You have
if RestHR ge 70 then delete;
and
where RestHR <= 70;
I don't think your issue is IF vs WHERE. It's how you treat the edge condition (i.e. RestHR=70). You are deleting 70's in the first usage, but keeping 70's in the second.
The WHERE analog to your IF … THEN DELETE statement should be
where RestHR <70
You have
if RestHR ge 70 then delete;
and
where RestHR <= 70;
I don't think your issue is IF vs WHERE. It's how you treat the edge condition (i.e. RestHR=70). You are deleting 70's in the first usage, but keeping 70's in the second.
The WHERE analog to your IF … THEN DELETE statement should be
where RestHR <70
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.