我的初始数据集有14000个STID变量,每个变量10 ^ 5。 我想通过每个stid制作一些程序,通过STID将修改输出到数据中,然后将所有STID一起设置在一个大数据集中,而不需要输出所有临时STID数据集。
我开始写一个MACRO:
data HAVE;
input stid $ NumVar1 NumVar2;
datalines;
a 5 45
b 6 2
c 5 3
r 2 5
f 4 4
j 7 3
t 89 2
e 6 1
c 3 8
kl 1 6
h 2 3
f 5 41
vc 58 4
j 5 9
ude 7 3
fc 9 11
h 6 3
kl 3 65
b 1 4
g 4 4
;
run;
/* to save all distinct values of THE VARIABLE stid into macro variables
where &N_VAR - total number of distinct variable values */
proc sql;
select count(distinct stid)
into :N_VAR
from HAVE;
select distinct stid
into :stid1 - :stid%left(&N_VAR)
from HAVE;
quit;
%macro expand_by_stid;
/*STEP 1: create datasets by STID*/
%do i=1 %to &N_VAR.;
data stid&i;
set HAVE;
if stid="&&stid&i";
run;
/*STEP 2: from here data modifications for each STID-data (with procs and data steps, e.g.)*/
data modified_stid&i;
set stid&i;
NumVar1_trans=NumVar1**2;
NumVar2_trans=NumVar1*NumVar2;
run;
%end;
/*STEP 3: from here should be some code lines that set together all created datsets under one another and delete them afterwards*/
data total;
set %do n=1 %to &N_VAR.;
modified_stid&n;
%end;
run;
proc datasets library=usclim;
delete <ALL DATA SETS by SPID>;
run;
%mend expand_by_stid;
%expand_by_stid;
但最后一步不起作用。我该怎么办?
答案 0 :(得分:2)
您非常接近 - 您需要做的就是删除宏循环中的分号并将其放在步骤3中的%end
之后,如下所示:
data total;
set
%do n=1 %to &N_VAR.;
modified_stid&n
%end;;
run;
然后产生你所追求的陈述:
set modified_stid1 modified_stid2 .... ;
而不是您最初生成的宏:
set modified_stid1; modified_stid2; ...;
最后,您可以使用delete语句中的stid:
删除所有临时数据集:
proc datasets library=usclim;
delete stid: ;
run;