BookmarkSubscribeRSS Feed
mfaqueiroz
Fluorite | Level 6

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,

🙂

 

 

4 REPLIES 4
Kurt_Bremser
Super User

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.

LinusH
Tourmaline | Level 20

@Kurt_Bremser 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
mfaqueiroz
Fluorite | Level 6

Hello,

I tried the your solution @Kurt_Bremser, 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,

🙂

Kurt_Bremser
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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