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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

3 REPLIES 3
Reeza
Super User

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?


 

ballardw
Super User

@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.

 

 

 

DonH
Lapis Lazuli | Level 10

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 3 replies
  • 1229 views
  • 14 likes
  • 4 in conversation