09-19-2011 09:51 AM
I have files with names defined by year and month. Essentailly, these files have exactly the same variables.
The file names are:
Can you please teach me how I can combine these files in a single data step?
Thanks a lot in advance.
09-23-2011 11:30 AM
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!.
%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*/
;/* to close set statement*/
/* other code*/
/* how to use*/
09-23-2011 12:01 PM
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 ' '
where libname='YOURLIB' and memname like 'DATA______'
order by 1 ;
* and used like ;
data together ;
set &names ;
09-26-2011 04:41 PM
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.