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

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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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