在sas中设置具有相似名称的多个数据集

Set multiple datasets with similar names in sas

假设我的工作环境中有不同数量的数据集,但所有这些数据集都以相似的名称开头:name_abc、name_efg、name_1ky 等。数据集具有相同的变量和特征,我想将它们都设置为一个数据集。

data bigdataset;
    set [all datasets that begin with name_];
run;

有没有一种方法可以在 SAS 中执行此操作而无需键入所有数据集?我需要它能够灵活处理工作环境中可用的数据集数量。

使用变量名通配符:

data bigdataset;
 set name_:;
run;

A colon following a variable name prefix selects any variable whose name starts with that prefix. This ability of the colon along with some simple naming standards enables the programmer to manage temporary variables better, format many variables quicker, determine unknown number of variables, clean up macro generated datasets, and shorten the code for variety of PROCS. For example

data ADLB;
set  lb:;

This DATA step reads all the data sets in the WORK library that begin with LB. Also, when the programmer coded this step, he/she did not need to know how many dataset are read, only that he/she wants to read all of the dataset with a particular prefix. Both colon and dash lists also work with the MERGE statement.

引自Using SAS Colon Effectively

您可以使用冒号修饰符,例如下面将合并 sashelp 库中以 prdsal 开头的所有数据集:

data all ;
 set sashelp.prdsal: ;
run;

无论数据集是否具有公共前缀,这都有效。当然,对于您的情况, COLON 修饰符是一个非常好的解决方案。

PROC SQL noprint;
    SELECT CATS(libname,".",memname) into :DSNS separated by " "
    FROM DICTIONARY.TABLES 
    WHERE UPCASE(LIBNAME)="YOUR_LIBNAME";
QUIT;
%Put DATA SETS: &DSNS;

Data BIGDATASET;
    Set &dsns;
Run;