I am still having trouble with date tokens. I have a date global macro variable and I want to compute another one that is 45 days earlier. I have tried both assigning with and without quotes and using %LET and call symput. I am using SAS 9.4. What am I doing wrong?
%LET pulldate = 11/29/2016 ;
/*%LET pulldate = '11/29/2016' ; */
Try 1:
data _null_ ;
%global earlyTerm ;
call symputX('earlyTerm' , %sysfunc(input(&pulldate., mmddyy10.)-45)) ;
run;
Try 2:
%LET earlyTerm = %sysfunc(input(&pulldate., mmddyy10.)-45))
%put &earlyterm. ;
You've got close on your second try.
If you really have to use the MM//DD/YYYY format for the PULLDATE var, this will do the trick:
* set;
%let pulldate = 11/29/2016 ;
%let earlyTerm = %eval(%sysfunc(inputn(&pulldate,mmddyy10.))-45);
* show;
%put &earlyterm.;
%put %sysfunc(putn(&earlyterm,mmddyy10.));
Use inputn/inputc or putn/putc with %sysfunc.
Some functions (like input/put) won't work with %sysfunc, more info here:
http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p1o13d7wb2zfcnn19...
Also, to perform the calculation (-45) you need to force the expression for evaluation, hence the %eval macro functions.
More on %eval: http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n07pr39df9k7m3n1w...
%sysevalf will do the trick, but is intended to be used with floating point arithmetic, which is not the case.
More on %sysevalf: http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p1d9ypna2tpt16n1x...
Hope it helps.
Daniel Santos @ www.cgd.pt
You're close. You're mixing data step and macro logic. I recommend data step if you're not familiar with macro functions.
Changes;
%LET pulldate = 11/29/2016 ;
data _null_ ;
call symputX('earlyTerm' , input("&pulldate.", mmddyy10.)-45, 'g') ;
call symputX('earlyTermDate' , put(input("&pulldate.", mmddyy10.)-45, date9.), 'g') ;
run;
%put &earlyTerm;
%put &earlyTermDate;
You could just use:
%let pulldate = %sysevalf('29nov2016'd);
%let earlyTerm =%sysevalf(&pulldate.-45);
HTH,
Art, CEO, AnalystFinder.com
You've got close on your second try.
If you really have to use the MM//DD/YYYY format for the PULLDATE var, this will do the trick:
* set;
%let pulldate = 11/29/2016 ;
%let earlyTerm = %eval(%sysfunc(inputn(&pulldate,mmddyy10.))-45);
* show;
%put &earlyterm.;
%put %sysfunc(putn(&earlyterm,mmddyy10.));
Use inputn/inputc or putn/putc with %sysfunc.
Some functions (like input/put) won't work with %sysfunc, more info here:
http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p1o13d7wb2zfcnn19...
Also, to perform the calculation (-45) you need to force the expression for evaluation, hence the %eval macro functions.
More on %eval: http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n07pr39df9k7m3n1w...
%sysevalf will do the trick, but is intended to be used with floating point arithmetic, which is not the case.
More on %sysevalf: http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p1d9ypna2tpt16n1x...
Hope it helps.
Daniel Santos @ www.cgd.pt
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.
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.