@mb402 wrote:
Hi!
I would like to learn how to read in and stack files from the previous 12 months all at once. The files are monthly text files with a XX month lag (ex: If I were to run an analysis in October, I would pull files from June if XX=05, but if I were to run an analysis in November, I would pull files from July). I also need to pull files for each of the 12 months prior. All the files have a name like zz_MON_YYYY.txt.
Step one is write the code to read one file.
Then you can make a design decision. Do you want to write one data step that reads all 12 files at once? Or read one file at a time and then combine the generated datasets.
For the first option modify the code to read from two files at once. Something like:
filename files ('zz_OCT_2019.txt','zz_SEP_2019.txt');
data want;
infile files .... ;
....
For the second option write the step that combines two of the files.
data want;
set month1 month2;
run;
See how to extend the pattern to 12 files.
For the issue of how to generate 12 months just use the INTNX() function.
data months;
start=today();
do offset=0 to -11 by -1 ;
next_month=intnx('month',start,offset);
output;
end;
format start next_month date9.;
run;