You can use data set
lists with the MERGE statement. Data set lists provide a quick way
to reference existing groups of data sets. These data set lists must
be either name prefix lists or numbered range lists.
Name
prefix lists refer to all data sets that begin
with a specified character string. For example,
merge
SALES1:;
tells SAS to merge all data sets starting with
"SALES1" such as SALES1, SALES10, SALES11, and SALES12.
Numbered
range lists require you to have a series of data
sets with the same name, except for the last character or characters,
which are consecutive numbers. In a numbered range list, you can begin
with any number and end with any number. For example, these lists
refer to the same data sets:
sales1 sales2 sales3 sales4
sales1-sales4
Note: If the numeric suffix of
the first data set name contains leading zeros, the number of digits
in the numeric suffix of the last data set name must be greater than
or equal to the number of digits in the first data set name. Otherwise,
an error will occur. For example, the data set lists sales001–sales99
and sales01–sales9 will cause an error. The data set list sales001–sales999
is valid. If the numeric suffix of the first data set name does not
contain leading zeros, the number of digits in the numeric suffix
of the first and last data set names do not have to be equal. For
example, the data set list sales1–sales999 is valid.
Some other rules to
consider when using numbered data set lists are as follows:
-
You can specify groups of ranges.
merge cost1-cost4 cost11-cost14 cost21-cost24;
-
You can mix numbered range lists
with name prefix lists.
merge cost1-cost4 cost2: cost33-37;
-
You can mix single data sets with
data set lists.
merge cost1 cost10-cost20 cost30;
-
Quotation marks around data set
lists are ignored.
/* these two lines are the same */
merge sales1-sales4;
merge 'sales1'n-'sales4'n;
-
Spaces in data set names are invalid.
If quotation marks are used, trailing blanks are ignored.
/* blanks in these statements will cause errors */
merge sales 1-sales 4;
merge 'sales 1'n - 'sales 4'n;
/* trailing blanks in this statement will be ignored */
merge 'sales1'n - 'sales4'n;
-
The maximum numeric suffix is 2147483647.
/* this suffix will cause an error */
merge prod2000000000-prod2934850239;
-
Physical pathnames are not allowed.
/* physical pathnames will cause an error */
%let work_path = %sysfunc(pathname(WORK));
merge "&work_path\dept.sas7bdat"-"&work_path\emp.sas7bdat" ;