Desktop productivity for business analysts and programmers

To_date between to Dates

Reply
Occasional Contributor
Posts: 5

To_date between to Dates

Hello,

I want to filter my table (Tab1) by the time gap between 2016-01-01 and 2016-01-31, so I wrote the follow code:

 

Tab1.FirstDate BETWEEN  To_Date(20160101,'YYYYMMDD') AND To_Date(20160131,'YYYYMMDD')

 

 

But SAS does not recognize the To_Date function. Do you have any alternative suggestion?

Thanks in advance for your help,

Smiley Happy

 

 

Super User
Posts: 9,612

Re: To_date between to Dates

Posted in reply to mfaqueiroz

Date literals in SAS are specified as "ddmmmyyyy"d.

In your case, you'd use "01jan2016"d and "31jan2016"d, respectively. No functions needed. You can also use single quotes.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 5,829

Re: To_date between to Dates

Posted in reply to mfaqueiroz

@KurtBremser described how to do it in SAS.

To_date is a proprietary function to Oracle. SAS adhere to ANSI SQL, with SAS language add-ons.

Data never sleeps
Occasional Contributor
Posts: 5

Re: To_date between to Dates

Hello,

I tried the your solution @KurtBremser, but the following error message appears:

 

 

ERROR: Expression using equals (=) has components that are of different data types.

 

I have to change the date format?

 

 

Thank you for your willigness to help,

Smiley Happy

Super User
Posts: 9,612

Re: To_date between to Dates

Posted in reply to mfaqueiroz

Please post the complete log of the step.

If you used the date literals exactly as I suggested, then your supposed date variable is not a date variable, but of type character.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 4 replies
  • 454 views
  • 2 likes
  • 3 in conversation