turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- How is it stored this boolean expression?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-01-2013 01:54 AM

Which way is faster?

Suppose I want to write the expression (k=1)*e+(k=2)*f and suppose that e,f need to be calculated. Does SAS calculate e,f , then (k=1)*e+(k=2)*f or does it evaluate first the boolean expressions (k=1) and (k=2) and then the corresponding e if k=1 is true or f if k=2 is true.

If SAS calculates both e and f then it is more efficient to do a conditional

if k=1 then do e;

else do f;

Accepted Solutions

Solution

04-01-2013
02:58 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-01-2013 02:58 PM

Yes, all the math will get performed. You might get some savings by switching as you suggest:

if k=1 then ...;

else if k=2 then ...;

In addition, this code works faster if k=1 most of the time. If k=2 most of the time, you could switch and test for k=2 first. But truthfully, the savings will be tiny, perhaps not even measurable. If you are interested in efficiency, you might post more of your code and get suggestions about how to speed it up.

Good luck.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-01-2013 06:11 AM

Why don't you write some code to test your assumption? Do each a million times and observe the time difference. You will need options FULLSTIMER.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-01-2013 01:18 PM

Here are references to help you understand the order of evaluation of an expression:

Logic: and, not, or

SAS(R) 9.3 Language Reference: Concepts, Second Edition

arithmetic:

SAS Operators in Expressions

SAS(R) 9.3 Language Reference: Concepts, Second Edition

Ron Fehd knot logically lazy maven

Solution

04-01-2013
02:58 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-01-2013 02:58 PM

Yes, all the math will get performed. You might get some savings by switching as you suggest:

if k=1 then ...;

else if k=2 then ...;

In addition, this code works faster if k=1 most of the time. If k=2 most of the time, you could switch and test for k=2 first. But truthfully, the savings will be tiny, perhaps not even measurable. If you are interested in efficiency, you might post more of your code and get suggestions about how to speed it up.

Good luck.