Hello SAS community,
I was able to tweak my date generating step, but I want to drop those date values into macro variables, but the values are not right? I'm using the symputx function for this task...
%Let Begin=6/30/2013;
%Let Periods=25;
data datesexp (keep=futdates);
do i=0 to &Periods;
futdates=intnx('month',input("&Begin",mmddyy10.,i,'end');
call symputx(cats('DtVar',put(_n_,8.)),futdates);
format futdates mmddyy10.;
output;
end;
run;
%put _user_;
Output is below, not in sync..
Assigned McrVar | Assigned McrVar (Convrt) | Generated | |
DTVAR1 | 20300 | 7/30/2015 | 6/30/2013 |
DTVAR2 | 19570 | 7/30/2013 | 7/31/2013 |
DTVAR3 | 19601 | 8/30/2013 | 8/31/2013 |
DTVAR4 | 19631 | 9/29/2013 | 9/30/2013 |
DTVAR5 | 19662 | 10/30/2013 | 10/31/2013 |
DTVAR6 | 19692 | 11/29/2013 | 11/30/2013 |
DTVAR7 | 19723 | 12/30/2013 | 12/31/2013 |
DTVAR8 | 19754 | 1/30/2014 | 1/31/2014 |
DTVAR9 | 19782 | 2/27/2014 | 2/28/2014 |
DTVAR10 | 19813 | 5/30/2014 | 3/31/2014 |
DTVAR11 | 19843 | 4/29/2014 | 4/30/2014 |
DTVAR12 | 19874 | 5/30/2014 | 5/31/2014 |
DTVAR13 | 19904 | 6/29/2014 | 6/30/2014 |
DTVAR14 | 19935 | 7/30/2014 | 7/31/2014 |
DTVAR15 | 19966 | 8/30/2014 | 8/31/2014 |
DTVAR16 | 19996 | 9/29/2014 | 9/30/2014 |
DTVAR17 | 20027 | 10/30/2014 | 10/30/2014 |
DTVAR18 | 20057 | 11/29/2014 | 11/30/2014 |
DTVAR19 | 20088 | 12/30/2014 | 12/31/2014 |
DTVAR20 | 20119 | 1/30/2015 | 1/31/2015 |
DTVAR21 | 20147 | 2/27/2015 | 2/28/2015 |
DTVAR22 | 20178 | 3/30/2015 | 3/31/2015 |
DTVAR23 | 20208 | 4/29/2015 | 4/30/2015 |
DTVAR24 | 20239 | 5/30/2015 | 5/31/2015 |
DTVAR25 | 20269 | 6/29/2015 | 6/30/2015 |
DTVAR26 | 20300 | 7/30/2015 | 7/31/2015 |
Hi,
You have to be careful with global macro variables. I suspect some of those values are from previous runs.
I noticed two issues:
1. missing closing parenthesis on input() function
2. On CALL SYMPUTX you use put _n_ for the numeric suffix. But _n_ will always be 1 (the datastep iterates only once). You probably want put (i,8.) .
Maybe something like below (I added date format to the symputx, which you may not want.
data datesexp (keep=futdates); do i=0 to &Periods; futdates=intnx('month',input("&Begin",mmddyy10.),i,'end'); call symputx(cats('DtVar',put(i,8.)),put(futdates,mmddyy10.)); format futdates mmddyy10.; output; end; run;
HTH,
--Q.
Hi,
You have to be careful with global macro variables. I suspect some of those values are from previous runs.
I noticed two issues:
1. missing closing parenthesis on input() function
2. On CALL SYMPUTX you use put _n_ for the numeric suffix. But _n_ will always be 1 (the datastep iterates only once). You probably want put (i,8.) .
Maybe something like below (I added date format to the symputx, which you may not want.
data datesexp (keep=futdates); do i=0 to &Periods; futdates=intnx('month',input("&Begin",mmddyy10.),i,'end'); call symputx(cats('DtVar',put(i,8.)),put(futdates,mmddyy10.)); format futdates mmddyy10.; output; end; run;
HTH,
--Q.
Thank you that worked.
You code is missing a paren somewhere.
But what is the actual question here?
Do you want the generated dates to start from July instead of June? If so then change the DO loop start and end values.
Do you want the generated macro variables to have the formatted dates instead of the number of days since 1/1/1960? If so then use PUT() function inside CALL SYMPUTX .
Thanks, those were exactly the anwers to my question. I'll continue refining my programming.
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.