假设在某个 library OUT 下面有多个数据,都以 ds_ 开头,想要合并所有数据,可以写:
data ds_all; set out.ds_:; run;
如果只想合并其中一部分数据,比如只合并 ds_1, ds_32 数据,有两种写法:
/*Method 1*/
data want; set out.ds_: indsname=indsname; if indsname=:'OUT.DS_1' or indsname=:'OUT.DS_32'; /*OR if scan(indsname,2,'.')='DS_1' or scan(indesname,2,'.')='DS_32'*/ run;
这里 indsname= 的作用是生成一个变量(here is indsname)并将SAS当前读入的数据的名字(out.ds_:)存储在这个变量中。这个变量不会在出现在生成的数据集里。可以通过显式定义将它显示出来:var=indsname;效果是:
VAR |
OUT.DS_1 |
OUT.DS_2 |
OUT.DS_3 |
... |
OUT.DS_32 |
这里=: 的作用是,the =: (equal-colon) was used to find all data set names that begin with DS_. it looks for strings that begin with whatever is in the quotes to the right of the =:
如果所有数据都是 DS_number, 那么有没有冒号结果都一样。如果数据是 DS_1, DS_2a, DS_11, ... 则需要用 =:
另外如果数据前缀是 DS_1,想要通过DS_1: 找到 DS_11, DS_12, ... 也是可以的。
第二种写法是:
/*Method 2*/
proc sql; select cats(libname,'.',memname) into :names separated by ' ' from dictionary.tables where libname="OUT" and memname in ('DS_1','DS_32'); quit; data want; set &names; run;
%put &names;
OUT.DS_1 OUT.DS_32
cats 的作用是连接字符串,并去掉字符串首尾空格。这里 libname 的值是OUT, memname 的值是的数据集的名字。
标签:set,32,ds,datasets,SAS,OUT,DS,indsname From: https://www.cnblogs.com/zooz-logging/p/16862229.html