1

I would need to do a loop over a list of variables inside a macro.

The list is created in the following way (I have started the name of the variables that I want with MO, nu or KA):

proc sql noprint; 
   select name into :varsi separated by ' ' 
   from dictionary.columns 
   where libname eq 'LABIMP' and  memname eq 'MUESTRA1' 
     and (NAME LIKE 'MO_%' OR NAME LIKE 'nu_%' or name like 'KA_%'); 
quit;

Then, I need to run a macro for each one... this macro is inside the following data step:

data labimp.muestra1;
   set labimp.muestra1;
   counter + 1;
   by nnumero_de_cliente;
   if first.nnumero_de_cliente then counter = 1;
   %addTendency(&varsi);
run;

Of course this way is not working because it brings all the variables at the same time. It's important that if I need a loop must remain inside the other datastep.....

I know it should be easy by I couldn't figure it out.

Thanks!!!!

2 Answers 2

1

The best way to do this is to design your proc sql step to create all of those macro calls.

proc sql ; 
select cats('%addTendency(',name,')'
  into :tendencyList separated by ' ' 
  from dictionary.columns 
  where libname eq 'LABIMP' and  memname eq 'MUESTRA1' 
  and (NAME LIKE 'MO_%' OR NAME LIKE 'nu_%' or name like 'KA_%'); 
quit;

That creates a list of %addTendency() calls that you then call by referencing &tendencyList (which I named, but you can name otherwise):

data labimp.muestra1;
set labimp.muestra1;

counter + 1;
by nnumero_de_cliente;
if first.nnumero_de_cliente then counter = 1;

&tendencyList.

run;
Sign up to request clarification or add additional context in comments.

1 Comment

This method is the easiest to debug.
0

You could do something like the following:

%do i=1 %to %sysfunc(countw(&varsi));
  %addTendency(%scan(&varsi, &i));
%end;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.