Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do nested comparison operators work?

Status
Not open for further replies.

Jubinell

Technical User
Oct 21, 2008
14
JP
Hi,

Simple question but I don't know what this is called so I haven't been able to find good results from the web.

Does something like this work in a data step?

where 0 < var < 6;


That is to say, is it always equivalent to

where var > 0 and var < 6;


I've tested with a made-up dataset and it seems to work fine. I'm just wondering if this practice is encouraged in sas programming.

Thank you.
 
Yes, this works, and I've not heard of any issues with it. I've seen it used several times as well.
Watch out for floating point problems when comparing numbers though. It's a good idea to round your "var" just in case the actual value of "var" is 5.9999999999999, when it should be 6. I've been hit by floating point errors twice in this way.

If you're really keen, I'd be interested to see a comparison of the two methods you've shown above for CPU time to see if there's any advantage one way or the other. Run the comparison on a few thousand records using one method, then on the same data using the other method, and see if the CPU time listed in the log is different.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top