BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mauley
Fluorite | Level 6

I am struggling to use macro variables within a macro.

 

For example:

 

%LET Run_dt = 31Mar2019;

%LET Report=%SYSFUNC(INTNX(MONTH,"&run_dt."d,0,e),DATE9.);

%LET start=%SYSFUNC(INTNX(MONTH,"&run_dt."d,-11,e),DATE9.);

%put &Report. &start.;

 

The Log will show

 

31MAR2019 30APR2018

 

But I would like to do this within a Macro (there will be part of something larger within the macro I'm not doing it without reason :))

 

Like this;

 

%Macro wont_work;

%LET Report=%SYSFUNC(INTNX(MONTH,"&run_dt."d,0,e),DATE9.);

%LET start=%SYSFUNC(INTNX(MONTH,"&run_dt."d,-11,e),DATE9.);

%Mend wont_work;

 

%month_prov;

 

This as I'm sure you know doesn't give me the results I want!

 

Please can someone explain my error to me?

 

Thankyou!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Make these two macro variable Global .

 

%LET Run_dt = 31Mar2019;

%Macro wont_work;
%global Report start ;
%LET Report=%SYSFUNC(INTNX(MONTH,"&run_dt."d,0,e),DATE9.);
%LET start=%SYSFUNC(INTNX(MONTH,"&run_dt."d,-11,e),DATE9.);
%Mend wont_work;

 

%wont_work

%put &Report. &start.;

View solution in original post

2 REPLIES 2
Ksharp
Super User

Make these two macro variable Global .

 

%LET Run_dt = 31Mar2019;

%Macro wont_work;
%global Report start ;
%LET Report=%SYSFUNC(INTNX(MONTH,"&run_dt."d,0,e),DATE9.);
%LET start=%SYSFUNC(INTNX(MONTH,"&run_dt."d,-11,e),DATE9.);
%Mend wont_work;

 

%wont_work

%put &Report. &start.;
mauley
Fluorite | Level 6

ThankYou! Makes sense ! 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 376 views
  • 0 likes
  • 2 in conversation