BookmarkSubscribeRSS Feed
di_niu0
Obsidian | Level 7

Hello, I have a problem with the below code. %gettime is a macro which gives the 100th day after the start date and outputs a table. I would like to get table1 which gives the 100th day after date1, table2 which gives 100th day after date2...Until date12. But the code only gives me table1. I am not sure what's wrong with the code. 

 

Thank you in advance! 

 

 

 

%macro date;

       %do i=1 %to 12;

                   %getdate(

                             start = date&i,

                              out = table&i);

       %end;

%mend;

 

%date;

6 REPLIES 6
Tom
Super User Tom
Super User

Not much information to work with:

image.png

Try this:

 

Spoiler

Modify the definition of the GETDATE macro and add this statement:

%local i;

 

 

di_niu0
Obsidian | Level 7
Hello, thank you for your reply. Do you mean add %local i into the GETDATE macro?
Tom
Super User Tom
Super User

Yes.  Your posted code is setting I=1 then calling GETDATE.  The %DO loop then increments I by 1 and tests if it is greater than 12.  So GETDATE must be changing I to a value that is 11 or larger.  If you tell GETDATE to use a LOCAL macro variable instead of the existing macro variable then it will not modify the variable being used for the %DO loop.

di_niu0
Obsidian | Level 7
Thank you!
Reeza
Super User

Look up CALL EXECUTE. 

The documentation has an example. 

 


@di_niu0 wrote:

Hello, I have a problem with the below code. %gettime is a macro which gives the 100th day after the start date and outputs a table. I would like to get table1 which gives the 100th day after date1, table2 which gives 100th day after date2...Until date12. But the code only gives me table1. I am not sure what's wrong with the code. 

 

Thank you in advance! 

 

 

 

%macro date;

       %do i=1 %to 12;

                   %getdate(

                             start = date&i,

                              out = table&i);

       %end;

%mend;

 

%date;


 

classe_i_k
Calcite | Level 5

Hi

I'm happy to help. However can you give an overview of your macro getname. 

 

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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
  • 6 replies
  • 2458 views
  • 1 like
  • 4 in conversation