SAS循环遍历宏内的变量列表(每次读取一个) [英] SAS Loop over a list of variables inside a macro (read one each time)

查看:35
本文介绍了SAS循环遍历宏内的变量列表(每次读取一个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对宏内的变量列表进行循环.

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

列表是按以下方式创建的(我已经用 MO、nu 或 KA 开始了我想要的变量名称):

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.

谢谢!!!!

推荐答案

最好的方法是设计你的 proc sql 步骤来创建所有这些宏调用.

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;

这会创建一个 %addTendency() 调用列表,然后您通过引用 &tendencyList(我命名,但您可以另外命名)来调用这些调用:

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;

这篇关于SAS循环遍历宏内的变量列表(每次读取一个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆