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;
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));
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.
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.
@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.
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.
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.
Ready to level-up your skills? Choose your own adventure.