I have files with names defined by year and month. Essentailly, these files have exactly the same variables.
The file names are:
data200906
data200907
data200908
data200909
data200910
data200911
data200912
data201001
data201002
data201003
......
data201107
data201108
Can you please teach me how I can combine these files in a single data step?
Thanks a lot in advance.
data all;
set data2:;
run;
Oh dear, that is really a magic Thanks a lot.
If I want to use some simple macro plus DO statement, how to achieve this? Just interested.
Your files are some txt files or datasets of sas ?
Ksharp
Since the %DO isn't allowed in open code you need a macro. The example below allows parameters to change the start and end year. It could be made more generic with a parameter for the base of the data set name as well. Pay attention to the positions of semicolons!.
%macro dname(syr=,eyr=);
data all;
set
%do yr=&syr %to &eyr;
%do m=1 %to 12;
%let m2= %sysfunc(putn(&m,z2.));/* this is to get the leading zeros*/
/* the %DO will not increment leading 0*/
data&yr.&m2
%end;
%end;
;/* to close set statement*/
/* other code*/
run;
%mend;
/* how to use*/
%dname(syr=2009, eyr=2011);
bncoxuk wrote:
Oh dear, that is really a magic Thanks a lot.
If I want to use some simple macro plus DO statement, how to achieve this? Just interested.
Since the DATA: approach became available only with SAS9.2, the macro approach and the follow method would be needed for earlier releases.
filling a macro variable with a list of the data set names is fairly straight forward :
proc sql noprint ;
select trim( libname) || '.' || memname into :names separated by ' '
from dictionary.members
where libname='YOURLIB' and memname like 'DATA______'
order by 1 ;
quit ;
* and used like ;
data together ;
set &names ;
run ;
Peter's solution is better than mine in that you won't reference any non-existant data sets. Mine was just to show one approach using an explicitly iterated %DO loop using the obvious pattern shown in the data set names.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.