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;
Extract the Date from Datetime using the datepart() function.
if '01APR2018'D <= DATEPART(DISCH_DT) <= '30JUN2018'D THEN output FY1819Q1;
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.