有一个sas宏可以根据名称,节,E_和名称创建多个数据集。 并且,每个数据集中都有一个“half_hr”列。现在,问题是要隔离所有数据集E_& name。基于half_hr ..说E_& name。& half_hr。
答案 0 :(得分:1)
假设e_name是您的e_& name数据集之一:
data e_name;
input other_variables $ half_hr $;
datalines;
a 1
b 17
c 4
d 12
e 7
;
run;
您希望获得该数据集中所有half_hr值的列表,并相应地进行子集化:
%macro subsetter;
proc sql noprint;
select distinct half_hr into: half_hr_list separated by " " from e_name;
quit;
data
%do i = 1 %to %sysfunc(countw(&half_hr_list.));
%let this_hh = %scan(&half_hr_list., &i.);
e_name&this_hh.
%end;;
set e_name;
%do i = 1 %to %sysfunc(countw(&half_hr_list.));
%let this_hh = %scan(&half_hr_list., &i.);
if half_hr = "&this_hh." then output e_name&this_hh.;
%end;;
run;
%mend subsetter;
%subsetter;