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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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