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

Hi,

 

I would like to filter out 'Stay_Date' before today. How could I change the following code in Data step?

 

Data Work.A;

     Set Work.B;

     Where Stay_Date LE 'sysdate'd;

Run;

 

It returns error: Invalid Date / Time. As 'Stay_Date' format is '2015-12-31'. But the following code is fine:

 

Data Work.A;

     Set Work.B;

     Where Stay_Date LE '25APR2017'd;

Run;

 

How could I use System date instead of a particular one? Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@Crubal wrote:

 

It returns error: Invalid Date / Time. As 'Stay_Date' format is '2015-12-31'


 

It seems you are confusing a few issues here. Stay_Date (without the quotes) is 2015-12-31 without the quotes, and this is a formatted date value, it is not a character string (which is what the quotes would indicate). Thus you need to compare Stay_Date to a SAS date value, for example:

 

 

where stay_date le today();

 

 No need for macro variables, or double-quotes to all the macro variable to be resolved.

--
Paige Miller

View solution in original post

3 REPLIES 3
Astounding
PROC Star

A couple of small changes:

 

     Where Stay_Date LE "&sysdate9"d;

 

It's important to use double quotes, so that the macro variable can resolve.

Crubal
Quartz | Level 8
Thank you that would be helpful for future Macro procedure!
PaigeMiller
Diamond | Level 26

@Crubal wrote:

 

It returns error: Invalid Date / Time. As 'Stay_Date' format is '2015-12-31'


 

It seems you are confusing a few issues here. Stay_Date (without the quotes) is 2015-12-31 without the quotes, and this is a formatted date value, it is not a character string (which is what the quotes would indicate). Thus you need to compare Stay_Date to a SAS date value, for example:

 

 

where stay_date le today();

 

 No need for macro variables, or double-quotes to all the macro variable to be resolved.

--
Paige Miller

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!

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
  • 1013 views
  • 2 likes
  • 3 in conversation