BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jbear
Calcite | Level 5

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
1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.

View solution in original post

4 REPLIES 4
Quentin
Super User

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.

The Boston Area SAS Users Group is hosting free webinars!
Next up: Joe Madden & Joseph Henry present Putting Power into the Hands of the Programmer with SAS Viya Workbench on Wednesday Nov 6.
Register now at https://www.basug.org/events.
Tom
Super User Tom
Super User

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 .

jbear
Calcite | Level 5

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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