macro call error

Reply
Contributor
Posts: 35

macro call error

[ Edited ]

 Hello,

 

I have started to figure out how can I use do loop in macro and I ran the below code (I found from this website). but I got error.

 

Here is the code: 

%macro control (list=, start_date=, end_date=);
   %local list;
   %do i=1 %to %sysfunc(countw(&list));
      %let key = %scan(&list,&i);
      %let key2= %scan(&start_date,&i); /* you already had the pattern for this statement*/
      %let key3= %scan(&start_date,&i);

       %macro_call(&key,&key2,&key3);
   %end;
%mend;

%control(list=1234 2456 3567 4567 5674 8765,
         start_date= 03-SEP-16  10-SEP-16 17-SEP-16 24-SEP-16 01-OCT16,
         end_date  = 09-SEP-16 16-SEP-16 23-SEP-16 30-SEP-16 07-OCT-16 );

and I got following error: 

 

 
 114                 %macro_call(&key,&key2,&key3);
                     _
                     180
 
 ERROR 180-322: Statement is not valid or it is used out of proper order.
 
 MLOGIC(CONTROL):  %DO loop index variable I is now 7; loop will not iterate again.
 
Thanks for any help;
Samira
PROC Star
Posts: 307

Re: macro call error

Is there actually a macro called "macro_call" defined and compiled somewhere?

 

I think the code you have is using it as an example of how to invoke one macro within another, but that macro has to exist.

Contributor
Posts: 35

Re: macro call error

Posted in reply to collinelliot

no actually that is all I have in my program. I am very new in SAS and I was trying to figure out how can I use such loops. and I thought macro_call is a defult statement in SAS. isn't?  If not how can I print out the variable within loop? 

 

yes I found the code at : https://communities.sas.com/t5/Base-SAS-Programming/How-can-access-a-macro-do-loop-or-do-loop-only-f...

 

Thank you for the reply!

Super User
Posts: 7,760

Re: macro call error

That post was written to illustrate calling a macro in a loop. macro_call is just a stand-in for any macro you need to execute repeatedly.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 11,343

Re: macro call error


samira wrote:

no actually that is all I have in my program. I am very new in SAS and I was trying to figure out how can I use such loops. and I thought macro_call is a defult statement in SAS. isn't?  If not how can I print out the variable within loop? 

 

yes I found the code at : https://communities.sas.com/t5/Base-SAS-Programming/How-can-access-a-macro-do-loop-or-do-loop-only-f...

 

Thank you for the reply!


To see the result of what you have done so far instead of the macro call use    %put key=&key key2=&key2 key3=&key3;

Super User
Super User
Posts: 7,039

Re: macro call error

Since you don't actually have another macro that you are calling (yet) then just put in a %PUT statement so you can see what vlaues you have assigned.

%put (&key1,&key2,&key3);

Also you do not need to add a %LOCAL statement for the macro parameters. They will already be local macro variables.  Instead you should define the macro variables you are creating as local. Otherwise you might change the values of existing macro variables.

%local i key1 key2 key3;

Note you also probably want to define KEY3 to take the value from the list of end dates instead of getting another copy of the start date.

Ask a Question
Discussion stats
  • 5 replies
  • 161 views
  • 1 like
  • 5 in conversation