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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 814 views
  • 0 likes
  • 3 in conversation