将变量值传递给数组

时间:2015-05-12 13:08:00

标签: arrays sas

数据集have包含一些前缀为Dex的列。但我不知道该前缀有多少列。

我想创建一个值等于这些列的数组。

data want;
set have;
array Dex[100];
for i = 1 to 100;
[assign values]
end;
run;

有没有办法在不知道这些列的名字的情况下做到这一点?

2 个答案:

答案 0 :(得分:2)

是的,你可以定义你的数组,如:

array vars Dex:;
do i=1 to dim(vars);
[assign values]
end;
run;

答案 1 :(得分:0)

使用dictionary.columns查找前缀为columns

dex的数量

/ 示例数据集 /

 data have;
    dex_random1=1;
    dex_1=2;
    dex_3=4;
    dex_dex_random=2;
  run;

    proc sql;
    select count(*) into: Number_of_vars from dictionary.columns where 
    upcase(libname)="WORK" and upcase(memname)="HAVE" and upcase(name) like "DEX%";
    select name into: All_vars separated by " " from dictionary.columns where 
    upcase(libname)="WORK" and upcase(memname)="HAVE" and upcase(name) like "DEX%";
    quit;

    data want(drop=i);
    set have;
    array dex[&Number_of_vars.] &All_vars.  ;
    do i=1 to &Number_of_vars.;
    dex[i]=1;
    end;
    run;