DATA Step, Macro, Functions and more

Question about SAS Tip: where also

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

Question about SAS Tip: where also

This is a response to SAS Tip: where also by @SAS_Tipster/@DonH since the topic is locked and replies are no longer allowed.

Is there a reason for using "also" over "and" in a where statement? Is one more efficient?


Accepted Solutions
Solution
‎04-20-2018 01:53 PM
Super User
Posts: 22,844

Re: Question about SAS Tip: where also

Usually this comes into play when you're possibly developing macros and you don't know how many conditions you may have. So its helpful to be able to create a line for each one with the ALSO without having to determine if you need an AND between each condition. 

There are multiple ways to account for this, but this is a nice option. 

 


@dgritt wrote:

This is a response to SAS Tip: where also by @SAS_Tipster/@DonH since the topic is locked and replies are no longer allowed.

Is there a reason for using "also" over "and" in a where statement? Is one more efficient?


 

View solution in original post


All Replies
Solution
‎04-20-2018 01:53 PM
Super User
Posts: 22,844

Re: Question about SAS Tip: where also

Usually this comes into play when you're possibly developing macros and you don't know how many conditions you may have. So its helpful to be able to create a line for each one with the ALSO without having to determine if you need an AND between each condition. 

There are multiple ways to account for this, but this is a nice option. 

 


@dgritt wrote:

This is a response to SAS Tip: where also by @SAS_Tipster/@DonH since the topic is locked and replies are no longer allowed.

Is there a reason for using "also" over "and" in a where statement? Is one more efficient?


 

Super User
Posts: 13,023

Re: Question about SAS Tip: where also


@dgritt wrote:

This is a response to SAS Tip: where also by @SAS_Tipster/@DonH since the topic is locked and replies are no longer allowed.

Is there a reason for using "also" over "and" in a where statement? Is one more efficient?


 I suspect that the complier spends a little more time constructing an internal equivalent of the where statement using and with actual execution not varying much. But you could build a set and try that.

 

Coding styles would be the main reason I think. Some folks just plain don't like really long statements. I'm not quite in that group but I do pay attention to coding style with such things.

 

Where also would also allow for single * line comments to test/modify code that might take a bit more care with longer statements.

 

 

 

Regular Contributor
Posts: 167

Re: Question about SAS Tip: where also

Reeza and ballardw beat me to it.

 

If if you look at the NOTE about the where clause, all of these variations produce the same note (for the sashelp.class data set):

 

  1. where age = 12 and sex = "M";
  2. where age = 12;
    where same and sex = "M";
  3. where also age = 12;
    where also sex = "M"

So I suspect this is all reconciled at compile time.

I like option 3 for both the multiple clauses issue (also applies to stored processes with parameters for multiple conditions) as well avoiding the case where adding a where clause later can replace the existing one. The also clause is just a reminder to check if there is already an active WHERE for the step.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 348 views
  • 14 likes
  • 4 in conversation