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

Hello,

I have a date variable which I'd like to use as a cut-off to select a set of observations (i.e. exclude all observations after 02/28/2013). The cut-off date will change when I run the program again in the future.

What would be the best way to do this in SAS given the date is stored as the number of days since 1/1/1960?

Would it be to create a variable which will convert my cut-off date to the number of days since 1/1/1960?

Thank you very much in advance for your feedback.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

As long as your dates are SAS dates (numeric, with date format) SAS can compare dates logically.

Store your reference date as a macro variable and use that in the comparison:

%let cutoff_date="01Jan2015"d;

Then in your code

if date <= &cutoff_date then ...

View solution in original post

3 REPLIES 3
Reeza
Super User

As long as your dates are SAS dates (numeric, with date format) SAS can compare dates logically.

Store your reference date as a macro variable and use that in the comparison:

%let cutoff_date="01Jan2015"d;

Then in your code

if date <= &cutoff_date then ...

Astounding
PROC Star

A couple of additional considerations ...

If it is possible your DATE variable will have a missing value, be sure to code for that:

if (. < date <= &cutoff_date);

Also, if your cutoff date has a pattern to it, you may be able to omit macro language entirely.  For example, suppose if you run the program in February you would like to include all dates before February 1 and exclude those from February 1 onward.  You could code:

if (. < date < intnx('month', today(), 0);

Under those conditions, you wouldn't need to modify the program at all in the future.  The cutoff date would adjust automatically.

Good luck.

Maisha_Huq
Quartz | Level 8

Thank you both so much.  That helps, would ve liked to mark both "Correct"

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
  • 13891 views
  • 4 likes
  • 3 in conversation