【问题标题】:Pass a dynamic array to iterate over proc sql传递一个动态数组来迭代proc sql
【发布时间】:2016-12-12 19:33:59
【问题描述】:

在这个问题上

Simple iteration through array with proc sql in SAS

%macro doit(list);
proc sql noprint;
%let n=%sysfunc(countw(&list));
    %do i=1 %to &n;
        %let val = %scan(&list,&i);
        create table somlib._&val as
        select * from somlib.somtable
        where item=&val;
    %end;
quit;
%mend;

%doit(100 101 102);

我想通过宏 doit 传递一个列表,我们可以从数据集中提取该列表。 例如:列表包含数据集“agegroups”中存在的变量“age”的不同值。

data agegroups;
input age;
datalines;
1
2
4
5
8
18
16
19
23;

我查看了 %macro 数组,但它没有帮助我 (http://www2.sas.com/proceedings/sugi31/040-31.pdf)

任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 听起来好像您正试图从单个大数据集创建大量小数据集。在 SAS 中,创建单个大型数据集并利用按组处理循环不同的值通常要简单得多。

标签: sql sas proc


【解决方案1】:

如 cmets 所述,按组处理可能是更好的选择。

但是,您可以使用 PROC SQL 来创建您的列表:

proc sql noprint;
select distinct age
   into :ageList separated by ' '
   from agegroups;
quit;

%put Age List: &ageList;

%doit(&ageList);

【讨论】:

    猜你喜欢
    • 2015-05-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    相关资源
    最近更新 更多