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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 459 views
  • 0 likes
  • 3 in conversation