Pyt*_*hon 2 macros concatenation sas
我知道如何从我的文件夹中调用不同的表。这是通过完成的function : %let x1 = libname.foldername。我的问题是如何使用简单的宏在1000个表上执行此操作
SAS
%Let Table1=project.table_201710;
%Let Table2=project.table_201711;
%Let Table3=project.table_201712;
%Let Table4=project.table_201801;
%Let Table5=project.table_201802;
%Let Table6=project.table_201803;
%Let Table7=project.table_201804;
%Let Table8=project.table_201805;
%Let Table9=project.table_201806;
%Let Table10=project.table_201807;
%Let Table11=project.table_201808;
%Let Table12=project.table_201809;
%Macro ConcatTable;
Data project.TABLE_FINALE;
Set
%Do i=1 %To 12;
&&Table&i.
%End;
;
Run;
%Mend ConcatTable;
%ConcatTable
Run Code Online (Sandbox Code Playgroud)
我会避免将数据从数据集中移到宏变量中。
要尝试的第一件事是根本不使用宏编码。尝试仅使用数据集列表。如果可以找到所需数据集的一个或多个公共前缀。
data project.TABLE_FINALE;
set project.TABLE_20: ;
run;
Run Code Online (Sandbox Code Playgroud)
如果您确实希望将列表放入宏变量中,那么从概念上讲它更清晰,并且仅将列表放入单个宏变量中即可简化编码。
proc sql noprint;
select dsname into :dslist separated by ' '
from mylist;
quit;
data project.TABLE_FINALE;
set &dslist;
run;
Run Code Online (Sandbox Code Playgroud)
但是,如果您确实有1,000个数据集,那么将其放入单个宏变量(限制为65K个字符)可能太多了。
您也可以只根据数据生成代码,而不必使用宏来生成代码。这样就无需将任何数据移动到宏变量中。例如,您可以使用CALL EXECUTE()。
data _null_;
set mylist end=eof;
if _n_=1 then call execute('data project.TABLE_FINALE; set');
call execute(' '||trim(dsname));
if eof then call execute(';run;');
run;
Run Code Online (Sandbox Code Playgroud)