DATA Step, Macro, Functions and more

Where clause understanding

Accepted Solution Solved
Reply
Super Contributor
Posts: 619
Accepted Solution

Where clause understanding

Appreciate if some of you help me understand what the following where clause will do?

 

WHERE '31Jan2017'd between t1.PREMIUM_BEG_DT AND t1.PREMIUM_END_DT

Accepted Solutions
Solution
‎03-01-2018 12:35 AM
Frequent Contributor
Posts: 109

Re: Where clause understanding

It will filter records where PREMIUM_BEG_DT<31-Jan-2017 and PREMIUM_END_DT>31-Jan-2017

View solution in original post


All Replies
Solution
‎03-01-2018 12:35 AM
Frequent Contributor
Posts: 109

Re: Where clause understanding

It will filter records where PREMIUM_BEG_DT<31-Jan-2017 and PREMIUM_END_DT>31-Jan-2017
Super User
Super User
Posts: 9,211

Re: Where clause understanding

This is basic SQL knowledge, perhaps have a read of the SQL in SAS help documents, or help documents on SQL:

https://www.w3schools.com/sql/sql_between.asp

PROC Star
Posts: 228

Re: Where clause understanding

Basically, it will select all rows where the begin-date is before or on the 31st of January  2017, and the end date is on that date or after. If you are doing standard SQL, that is (in SAS, that happens if you write Pass-through SQL calls, or if the where clause is passed directly to an external DBMS).

 

But, if you are doing SAS SQL, it can also be the opposite, if the begin date is larger than the end date. Including if the end date is missing, and the begin date is after the date in question. SAS has a problem with missing values in where clauses, and with the between condition.

 

 

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 112 views
  • 3 likes
  • 4 in conversation