You need to combine the data into a single data set. This is either a MERGE or SET in a DATA step, or a JOIN in PROC SQL. Since we don't have your data, you will have to do this part.
Then to do the summing, you want PROC SUMMARY. Example:
proc summary nway data=have;
class name;
var payment;
output out=sums sum=sum_payment;
run;
If you need to keep the separate datasets, create a view:
data dataview/view=dataview;
set
data1201
data1202
data1203
......
;
run;
and then run proc summary over that.
Remove the semicolons between the table names. The syntax needs to be a SET statement with a list of tables name and then a single semicolon which terminates the statement.
If code has errors then also please always the SAS log which shows the actual error message.
Use call execute() in a data step to create the actual data step:
data _null_;
period = '01mar2002'd;
call execute('data want; set');
do until (period > '01dec2019'd);
call execute(' data' !! substr(put(year(period),z4.),3,2) !! put(month(period),z2.));
period = intnx('month',period,1,'b');
end;
call execute(';run;');
run;
If all of the desired input data sets start with "tab", you can do
data comp;
set tab:;
run;
Please don't ask the same question twice. This only messes up discussions. @Kurt_Bremser has already given you a working answer here.
I merged this back into the original question.
You can use the method I posted with any prefix, and any dataset with an additional suffix will be excluded.
@Yona22 wrote:
Hi, I have lots of dataset and named with year and months (TAB0203, TAB0204,..... until TAB1912). I want to extract all of them. This is my code
DATA COMB;
SET TAB0203
TAB0204
....
TAB1912;
RUN;
But it only read the 3 dataset and didn't read the rest of the data from TAB0205 until TAB1911. May I know how should I write for the code in order to read all of them?
AS was suggested before: COPY the LOG and paste the copied text into a code box opened on the Forum with the {I} or "running man" icon.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.