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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 904 views
  • 0 likes
  • 3 in conversation