BookmarkSubscribeRSS Feed
Ranjeeta
Pyrite | Level 9

04APR2018:00:00:00

I have dates in the above format in the sas dataset that is datetime 20 but my code below does not extract the records for Q1 which should be any records that fall between and are equal 1st April 2018 to 30 June 2018

Please advise

 

data FY1819Q1;
set EVT.SP440_FY2018Q2;
if '01APR2018'D <= DISCH_DT <= '30JUN2018'D THEN output FY1819Q1;
run;

2 REPLIES 2
SuryaKiran
Meteorite | Level 14

Extract the Date from Datetime using the datepart() function.

 

if '01APR2018'D <= DATEPART(DISCH_DT) <= '30JUN2018'D THEN output FY1819Q1;
Thanks,
Suryakiran
ballardw
Super User

@Ranjeeta wrote:

04APR2018:00:00:00

I have dates in the above format in the sas dataset that is datetime 20 but my code below does not extract the records for Q1 which should be any records that fall between and are equal 1st April 2018 to 30 June 2018

Please advise

 

data FY1819Q1;
set EVT.SP440_FY2018Q2;
if '01APR2018'D <= DISCH_DT <= '30JUN2018'D THEN output FY1819Q1;
run;


Your example value show time components and would be a SAS DATETIME value, not a date. When you want to use only the DATE portion of such a variable the function Datepart would be used on the value.

 

Try

data FY1819Q1;
set EVT.SP440_FY2018Q2;
if '01APR2018'D <= datepart (DISCH_DT) <= '30JUN2018'D THEN output FY1819Q1;
run;

https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 432 views
  • 0 likes
  • 3 in conversation