BookmarkSubscribeRSS Feed
wendydawn
Calcite | Level 5

Hello, 

 

I'm new to macros and have some very simple code which seems to be working. I tested it by printing out the dates and dates2 tables:

 

CODE

%MACRO createtables (row, seeddate);

data dates;
runmonth = &seeddate.;
run;

%mend;

 

createtables (row=1, seeddate=mdy(2,1,2022));

 

data dates2;
set dates;
testa = put(runmonth,yymmdd10.);
run;

wendydawn_0-1693246992887.png

 

But when I take the next step using rundate in INTNX, I get an error that rundate is not a number. What am I doing wrong?? Thanks in advance for your help.

CODE

%MACRO createtables (row, seeddate);

data dates;
runmonth = &seeddate.;
startdate = %sysfunc(intnx('month',runmonth,-12,'B'));
run;
%mend;


%createtables (row=1, seeddate=mdy(2,1,2022));

wendydawn_1-1693247166444.png

 

 

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

No need for %sysfunc to call a data step function inside a data step. Just use the data step function.

 

%MACRO createtables (row, seeddate);
    data dates;
        runmonth = &seeddate.;
        startdate = intnx('month',runmonth,-12,'B');
    run;
%mend;

 

You can simplify this code even further

 

%macro createtables (row, seeddate);
    data dates;
        startdate = intnx('month',&seeddate,-12,'b');
    run;
%mend;

 

Also, if you MUST use %sysfunc, do not put quotes around month and do not put quotes around B. But even so, you can't use %sysfunc here because it cannot access any data step variables, in this case it cannot access data step variable RUNMONTH.

--
Paige Miller
wendydawn
Calcite | Level 5

Thank you so much! I really appreciate your response. I feel like I tried everything but the simplest solution. 🙃 I still have a lot to learn about data steps vs other types of steps.

Tom
Super User Tom
Super User

@wendydawn wrote:

Thank you so much! I really appreciate your response. I feel like I tried everything but the simplest solution. 🙃 I still have a lot to learn about data steps vs other types of steps.


You need to learn how to use data steps first.  Do not bother trying to learn how to use code to create code (the macro language) until you know how to create the code yourself.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 591 views
  • 0 likes
  • 3 in conversation