Yes, for sure; that's basically what I have now. The issue is that there are 100 variables, not just age and sex. And so if I want to make a table that only uses like 20 of the 100 variables, I basically have them all in a list and comment out the ones I don't want to read in. However, as it is now, I'd have to do the same process (manually curating a list of variables and their corresponding value labels). It would be easier if I could just have something that reads in the data, then makes a list, then checks that list against a list of formats and then just does all that automatically. So this reads in first quarter 2007 and 2017. But imagine the list of variables like 10x as long and so I just comment out most of them. options minoperator mindelimiter=','; %macro doloop; data _null_; /* Start year */ call symput ("startyear",'2007'); /* Start month */ call symput ("startmonth",'01'); /* End year */ call symput ("endyear",'2017'); /* End month */ call symput ("endmonth",'04'); /* Only specific months */ call symput /*("limitmonth",'');*/ ("limit",'and (&i in (2007,2017) and &month in(01,02,03,04))'); /*for all months in range leave everything between single quotes blank*/ stop; run; /* This section starts the do loop logic */ %do i=&startyear %to &endyear; %do j=1 %to 12; %if &j.=1 and &i.=&startyear %then %let j=&startmonth; /* on first loop, sets &startmonth (instead of defaulting to 1)*/ %let month=%sysfunc(putn(&j,z2.)); /* leading 0 for month if needed */ %let year=%sysfunc(substrn(&i.,3)); /* last 2 digits of year */ %if ( ((&endyear. ne &startyear) and (&i. ne &endyear)) OR (&i.=&endyear and &month. le &endmonth) ) /* continues if not end year OR if end year but less or equal to endmonth */ &limit /*continues if conditions from symput above are met*/ %then %do; /* continues... */ data TAB&month.&year.; /* start data step*/ %if &i>=2017 %then /* use pre-release folder if year >= 2017 */ %do; infile "\\DIRECTORY1\20&year.\tab&month.&year..prn" lrecl=430 missover; %end; %else /* use main tabs folder if not >= 2017 */ %do; infile "\\DIRECTORY2\tab&month.&year..prn" lrecl=430 missover; %end; /*__ STEP 2: INPUT DESIRED VARIABLES _________________________________________________________________________________________________*/ input @6 DWELID $18. /* Dwelling ID */ @29 SYEAR 4. /* Survey year - yyyy */ @29 SDATE 6. /* Survey year and month yyyymm */ @33 SMONTH 2. /* Survey month - mm */ @63 FINALWT 5. /* Final weight for respondent */ @119 AGE_TABS 3. /* Age of respondent as of end of /* @125 EDUCLEV 1. /* Highest level of edu (break at 1990) */ ... ; /*this semicolon needs to stay (ends the DATA step)*/ %include "\\DIRECTORY1\PROC_FORMAT2.sas"; /* brings in formats*/ run; %end; /* end restriction for going past end month */ %end; %end; /* end main start/end month/year do loops */ %mend; %doloop;
... View more