BookmarkSubscribeRSS Feed
Xinhui
Obsidian | Level 7

I have a variable called _datadate. The format of this variable is "MMDDYY10." Our data date ranges from 05/01/2015 to 07/31/2017.

 

I have two questions. First, I need to delete all of the dates before 05/15/2015.  I use the following code to attempt this, but it does not work. How will I be able to accomplish this?

IF _datadate GE 05/15/2015 then OUTPUT;

The second question is as follows: 

 

I want to get all of the DD values equal to 14 and 15. I want a function that will detect all of 14th and 15th of each month. How can I do this?

3 REPLIES 3
Reeza
Super User

1.check the list of functions - DAY() 

2. Date liberals are specified as 'ddMONyyyy'd or ‘01Jan2017’d

 

All of this is documented here:

http://documentation.sas.com/?docsetId=lrcon&docsetTarget=p1wj0wt2ebe2a0n1lv4lem9hdc0v.htm&docsetVer...

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Avoid coding in uppercase.

For your example:

data want;
  set have;
  where _datadate ge '15MAY2015'd and day(_datadate) in (14,15);
run;
Astounding
PROC Star

Those are the right tools, but the program needs a tweak:

 

data want;

set have;

where _daydate >= '15May2015'd;

if day(_daydate) in (14, 15) then delete;

run;

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
  • 763 views
  • 0 likes
  • 4 in conversation