Storing generated dates using symputx (Macro Var Values are incorrect?)

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

Storing generated dates using symputx (Macro Var Values are incorrect?)

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 McrVarAssigned McrVar (Convrt)Generated
DTVAR1203007/30/20156/30/2013
DTVAR2195707/30/20137/31/2013
DTVAR3 196018/30/20138/31/2013
DTVAR4196319/29/20139/30/2013
DTVAR51966210/30/201310/31/2013
DTVAR61969211/29/201311/30/2013
DTVAR71972312/30/201312/31/2013
DTVAR8197541/30/20141/31/2014
DTVAR9197822/27/20142/28/2014
DTVAR10198135/30/20143/31/2014
DTVAR11198434/29/20144/30/2014
DTVAR12198745/30/20145/31/2014
DTVAR13199046/29/20146/30/2014
DTVAR14199357/30/20147/31/2014
DTVAR15 199668/30/20148/31/2014
DTVAR16199969/29/20149/30/2014
DTVAR17 2002710/30/201410/30/2014
DTVAR182005711/29/201411/30/2014
DTVAR192008812/30/201412/31/2014
DTVAR20201191/30/20151/31/2015
DTVAR21201472/27/20152/28/2015
DTVAR22201783/30/20153/31/2015
DTVAR23202084/29/20154/30/2015
DTVAR24202395/30/20155/31/2015
DTVAR25202696/29/20156/30/2015
DTVAR26203007/30/20157/31/2015

Accepted Solutions
Solution
‎07-25-2013 12:44 PM
PROC Star
Posts: 1,322

Re: Storing generated dates using symputx (Macro Var Values are incorrect?)

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.

View solution in original post


All Replies
Solution
‎07-25-2013 12:44 PM
PROC Star
Posts: 1,322

Re: Storing generated dates using symputx (Macro Var Values are incorrect?)

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.

Contributor
Posts: 29

Re: Storing generated dates using symputx (Macro Var Values are incorrect?)

Thank you that worked.

Super User
Super User
Posts: 7,037

Re: Storing generated dates using symputx (Macro Var Values are incorrect?)

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 .

Contributor
Posts: 29

Re: Storing generated dates using symputx (Macro Var Values are incorrect?)

Thanks, those were exactly the anwers to my question. I'll continue refining my programming. Smiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 758 views
  • 3 likes
  • 3 in conversation