g********3 发帖数: 123 | 1 I want to stack several sas datasets from one directory:
a_20120101
a_20120102
a_20120105
a_20120106
b_20120107
Any dataset like a_2012xxx is what I need. but the number is not consistent,
and b_20120107 should not be included.
what should I do? |
d******9 发帖数: 404 | 2 try to use dread function |
p***r 发帖数: 920 | 3 x command
【在 d******9 的大作中提到】 : try to use dread function
|
d******9 发帖数: 404 | 4 Or use macro to do it. Below codes works well, tested with few sample
datasets.
options mprint symbolgen;
data A_201201;
A=225;
run;
data A_201207;
A=226;
run;
data A_201205;
A=338;
run;
data R_201207;
A=338;
run;
data B_201279;
A=551;
run;
proc sql;
select memname into : tables separated by ' '
from sashelp.vtable
where libname='WORK' and upcase(substr(memname, 1,1))='A';
quit;
data combine;
set &tables;
run;
=============================
LOG:
45 data combine;
SYMBOLGEN: Macro variable TABLES resolves to A_201201 A_201205 A_201207 A_
201279
46 set &tables;
47 run;
NOTE: There were 1 observations read from the data set WORK.A_201201.
NOTE: There were 1 observations read from the data set WORK.A_201205.
NOTE: There were 1 observations read from the data set WORK.A_201207.
NOTE: There were 1 observations read from the data set WORK.A_201279.
NOTE: The data set WORK.COMBINE has 4 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
|
A****t 发帖数: 141 | 5 用macro会方便一点
data _null_;
length filename $ 10;
input filename $;
call symput('y'||left(_n_), filename);
datalines;
a_20120101
a_20120102
a_20120105
a_20120106
b_20120107
;
run;
%put &y1 &y2 &y3 &y4 &y5; |
g********3 发帖数: 123 | 6 Thank you very much, both work! |