SAS Nested Macro with Do Loop

35 views Asked by At

I have this SAS macro:

%let values_list =JUBILADOS RIONEGRO MERCADOABIERTO;
%macro apply_where_condition(values_list);
  %let num_values = %sysfunc(countw(&values_list));
  %do i = 1 %to &num_values;
    %let current_value = %qsysfunc(scan(&values_list, &i));
    %date_loop_inicial(01JAN2022,01JAN2023,&current_value.)
  %end;
%mend;
%apply_where_condition(&values_list);

The problem is that the do loop when I put the nested macro it only does one iteration. But without that it works fine. The nested macro does just a bunch of operations on table and at the last part inserts the data to an empty table.

I expected for it to iterate over all the values and it only iterates once.

1

There are 1 answers

0
Tom On

Share the code that defines the other macro.

Most likely date_loop_inicial is modifying the value of the macro variable I.

The other macro should create a LOCAL macro named I so that it cannot modify the value of I used in apply_where_condition.

If you cannot fix date_loop_inicial then change your %DO loop to use a different name for its macro variable.

Get in the habit of defining any local macro variables your macros need so that you can call those macros without the risk of modifying an existing macro variable that just happens to use the same name.

As an example, you should add this line right after the %MACRO apply_where_condition; statement

%local num_values i current_value ;