我上具有以下结构的数据集工作:SAS MACRO循环
Color Apple Orange Grape Avocado Blueberry
Yellow 1 . . . .
Orange . 1 . . .
Purple . . 1 . 1
我想写每个果型创建表,选择所有的颜色(行)的宏有一个值为1.例如,苹果TBL_APPLE的表格将有如下4行:
目前我正在考虑循环遍历行和列。作为弗里斯特一步,我打开所有的行和列变量引入宏:
/*rows*/
proc sql noprint;
select count(*) into :Nobs
from work.fruit;
select Color into :Attr1-:Attr%left(&Nobs)
from work.fruit;quit;
/*columns*/
proc contents data=work.fruit out=contents noprint; run;
%let n=&sqlobs;
proc sql; select name into :fruit1-fruit%left(&n) from contents; quit;
%macro fruit;
%do i=1 %to &NObs;
%do j=1 %to &n;
proc sql;
create table tlb_&&fruit&j as
select *
from work.fruit
where &n = &n;
quit;
%end;
%end;
%mend fruit;
%fruit;