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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.