08-11-2016 02:39 PM
08-11-2016 03:45 PM
It looks like you might be adding to your use of macros, rather than reducing it. Consider this macro:
%macro dates (month=, start_yr=, end_yr=);
%do yr=&start_yr %to &end_yr;
%date (&yr, &month)
Now you would have to call this macro just once to loop through all the Junes:
%dates (month=06, start_yr=11, end_yr=16)
Is that easier? Perhaps.
08-11-2016 04:12 PM
To read in your data, I suggest you use a macro %do loop in place of calling the macro over and over. I worked up an example of the logic you can use:
options mprint symbolgen;
yr=year(today())-2000; /* to get a 2 digit year*/
call symput('thisyear', left(put(yr,8.)));
call symput ("month1",'06');
call symput ("month2",'07');
%do i=&lastyear %to &thisyear;
%do j=1 %to 2;
Replace the second data null step with your data step that reads in the text file.
You can use similar logic to create one data set that contains all the data. Then to compute your average change you can follow the logic from this example in the PROC MEANS documentation:
08-16-2016 12:59 PM
Thanks so much. I've been playing with this to get it to work. I am still running into two problems:
1. the current month's dataset is kept in a different folder from the previous months'. So I tried to add a condition to the data step, but it is not working. Just tries to take everything from the pre-release folder (see text in red):
08-16-2016 01:32 PM
Also, how can I combine these 12 datasets into 1 final dataset (ideally with the columns for the change between months).
08-16-2016 02:15 PM
Your expanding your question when you don't have your first one complete....one step at a time.
Here's a method that will work, you should fix the filename list to be reflective of your file names. But it works without macros and is easier to understand and read. It's untested so there's probably errors, but it should be relatively easy to debug.
The data step creates a file list with the list of file names.
The second data step reads all the files into one dataset, with a variable that identifies the source.
data file_list; do i=1 to 16; do j=1 to 2; if i=16 and j=2 then file_name=catt("\\lhs4\prerelease\ANALYSIS\DATA\TABS\20", put(i, z2.), "\tabmonth", j, ".prn"); else filename=catt("\\fld8filer\Tabs\tabmonth", j, put(i, z2.), ".prn"); output; end; end; run; filename placehold; data want; set file_list; infile placehold filevar=file_name filename=filename eov=eov lrecl=430 missover; input @; if _n_ eq 1 or eov then do; txt_file_name=scan(filename, -1, "\"); eov=0; end; else input @6 PROV 2. /* PROV */ @29 SYEAR 4. /* Year */ @33 SMNTH 2. /* Month */ @29 SDATE 6. /* Survey year and month - yyyymm */ @122 SEX $CHAR1. /* Sex of respondent. */ @140 NAICS 2. /* Industry 2-digit */ @140 NAICS4 4. /* Industry 4-digit */ @144 SOC4 $CHAR4. /* occupation 4-digit */; if missing(AGE_TABS) then AGEGROUP_main=.; else if AGE_TABS LT 15 then AGEGROUP_main=1; /* LT 15 */ else if 15 LE AGE_TABS LT 25 then AGEGROUP_main=2; /*15-24 */ else if 25 LE AGE_TABS LT 55 then AGEGROUP_main=3; /* 25-54 */ else AGEGROUP_main=4; /* 55+ */ run;
08-12-2016 01:39 AM - edited 08-12-2016 01:41 AM
Did you know that you can include multiple files in a filename statement and read them all in at once?
Especially if they have the same format.
Filename myfiles ('file1' 'file2' 'file3');
And then in the infile statement include the myfiles in place of the file path.
Infile myfiles ...;
Or you could dynamically build your filename and use the FILEVAR option to read them all at once and not have a macro at all.
Example 10 in the documentation
If you use the dynamic option you can programmatically change it for the last record so although the path is different the same process will work. Use an If/Then.