BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
souji
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

1 REPLY 1
mkeintz
PROC Star

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
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1031 views
  • 5 likes
  • 2 in conversation