I have a macrovariable called &filterdate_start. It's DATETIME20 and has the value 26NOV2012:00:00:00.
I need a new macrovariable called &filterdate_end to equal &filterdate_start + 2 days, with the value 28NOV2012:00:00:00.
What's the most practical way to add 2 days to a DATETIME20 value?
If you want the same time of day, just add 2 * 24 * 60 * 60.
If you want the same time of day, just add 2 * 24 * 60 * 60.
I'd use one of SAS's most powerful date/datetime functions: INTNX
Somewhat like
%let filterdate_end = %sysfunc( intnx( dtday, "&filterdate_start"dt, 2 ) , datetime20. ) ;
Two assumptions here: &filterdate_start is the formatted datetime value, &filterdate_end is expected to be in datetime20. format.
If not then
%let filterdate_end = %sysfunc( intnx( dtday, &filterdate_start, 2 ) ) ;
will do and return the result as the number of seconds since SAS epoch (formatting then left to you).
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.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.