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.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: 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.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: 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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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