UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS Code Fragments
Combining Multiple SAS Files Using a Macro with the "set" command

If you had 2 SAS data files, say "file1" and "file2", you could combine them using a program like...

data both;
  set file1 file2 ;
run;

If, however, you had 200 SAS data files, say "file1" "file2" ... "file200" then this would be alot of typing doing the "set" statement for 200 files.  Instead, you can make a SAS macro as shown below.  This macro just combines "file1" and "file2", but can be extended to read multiple files.

data file1;
  input a;
cards;
1
2
3
;
run;

data file2;
input a;
cards;
4
5
6
;
run;

%macro combine;

data big;
  set
  %do i = 1 %to 2;
    file&i
  %end;
  ;
run;

%mend;

%combine;

proc print data=big;
run;


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California