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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.