如何阅读多个特定数据集并附加到一个大数据集?
例如我在库中我有100个数据集,但我只想附加有_du1,_du2
的数据集格式和列名相同
我对它的刺痛无效:
PROC SQL NOPRINT;
SELECT memname INTO :tab1-:tab103 FROM sashelp.vtable
where memname like '_DU%';
SELECT count(*) INTO :obs FROM sashelp.vtable
where memname like '_DU%';
QUIT;
%macro rubber;
%do i=1 %to i=&obs;
proc append base=tot_comb data=&&tab&i force;
run;
%end;
%mend;
%rubber;
答案 0 :(得分:5)
data tot_comb;
set work._DU:; *or your libname;
run;
如果您使用的是SAS 9.2或更高版本,这将有效。如果您使用的是9.1或更早版本,则需要执行一个proc sql步骤,例如
proc sql;
select memname into :namelist separated by ' '
from dictionary.columns
where libname='WORK' /* or your libname */
and memname eqt '_DU';
quit;
*eqt is like starts with;
data tot_comb;
set &namelist;
run;
只需要一次写入,我不确定它会比PROC APPEND的那么多次调用慢得多。
答案 1 :(得分:1)
以下是一些代码,它将从给定库中获取具有某些特征的所有数据集名称(以_DU开头)。您可以通过各种方式使用最终宏来附加数据集。
Data _DU1;
var="One";
Run;
Data _DU2;
var="Two";
Run;
PROC SQL;
create table main as
SELECT *
FROM DICTIONARY.COLUMNS
WHERE UPCASE(LIBNAME)="WORK" AND
UPCASE(MEMNAME) like '_DU%';
Select memname
into :dsn separated by ' '
from main;
QUIT;
%Put &dsn;
编辑(根据您的评论)
我添加了一些UPCASE语句,并使用了count宏变量来表示选项卡宏的数量 缩小where语句应该可以提高代码效率
试试这个(部分代码未经测试):
PROC SQL NOPRINT;
SELECT count(*)
INTO :obs
FROM sashelp.vtable
where UPCASE(LIBNAME)="<YOUR LIB IN UPCASE>" AND
upcase(memname) like '_DU%';
%Let obs=&obs;
SELECT memname
INTO :tab1-:tab&obs
FROM sashelp.vtable
where UPCASE(LIBNAME)="<YOUR LIB IN UPCASE>" AND
upcase(memname) like '_DU%';
QUIT;
%macro rubber;
%do i=1 %to &obs;
proc append base=tot_comb data=&&tab&i force; run;
%end;
%mend;
%rubber;