x cd /pub/data/acs/Tools; %let pgm=gen_acsvarlist_v2; filename pgm "&pgm..sas"; /* Program to access the variables metadata set for latest ACS 5-year cycle to generate macro variables ACSMEANS, ACSMWTS, PCTVARS, and PCTWTS, which can be used to aggregate the 5-year datasets. We do separate set for the BG data sets. */ %let year = 2024; %include '/pub/sas/autoexec.sas'; libname acs&year "/pub/data/acs&year"; libname acs (acs&year); libname user '/SAS_temp'; options nosymbolgen nomprint source ; *options symbolgen mprint mlogic source ; /* qwords macro returns a series of quoted words from a string of text not containing any quotes. (e.g., January February March --> "January" "February" "March") Blanks are delimiters on input. If dlmtr is specified, the output string has words separated by that string rather than the default blanks. */ %macro qwords(in, dlmtr=%str( )); %local n word; %let n = 1; %let word = %scan(&in, 1, %str( )); %do %while (&word ne %str()); "&word" &dlmtr %let n = %eval(&n + 1); %let word = %scan(&in, &n, %str( )); %end; %mend qwords; /* varlist macro is a modification of the original to handle just these special uses. */ %macro varlist (_ds); %let _list = ; %let _dsid = %sysfunc(open(&_ds)); %do _i = 1 %to %sysfunc(attrn(&_dsid, NVARS)); %let _vname = %sysfunc(varname(&_dsid, &_i)); %let _vtype = %sysfunc(vartype(&_dsid, &_i)); %if &_vtype = N %then %let _list = &_list &_vname; %end; &_list %mend varlist; data variables5; retain acs5yrvars "%varlist(acs.ustracts5yr)" ; acs5yrvars = upcase(acs5yrvars); set acs.variables5yr(keep=variable_name percent_variable wtvar univvar); if index(acs5yrvars, trim(upcase(variable_name))) then output; drop acs5yrvars; run; proc sql noprint; select percent_variable into :pctvars separated by " " from variables5 where percent_variable ne ' '; select univvar into :pctwts separated by " " from variables5 where percent_variable ne ' ';; select variable_name into :means separated by " " from variables5 where wtvar ne ' '; select wtvar into :mwgts separated by " " from variables5 where wtvar ne ' '; quit; data _null_; set acs.ustracts5yr(keep= &pctvars &means); * This will trigger errors when we have variables not on dataset. ; stop; run; %put _global_; * See code below for BGs. We should be able to automate the generation of the parms file. ; * Generate the aggvarsparms&year..sas file that will be used in CAPS ACS when processing tract-level data. ; filename trparms "/pub/data/acs/Tools/aggvarparms&year..sas"; data _null_; file trparms linesize=132 flowover; put "* Generated by program in acs/Tools/&pgm..sas at &systime on &sysdate .; "; put '%let ACSMEANS=' %qwords(&means, dlmtr=%str( +1 )) ';' /; put '%let ACSMWGTS=' %qwords(&mwgts, dlmtr=%str( +1 )) ';' /; put '%let PCTVARS=' %qwords(&pctvars, dlmtr=%str( +1 )) ';' /; put '%let PCTWTS= ' %qwords(&pctwts, dlmtr=%str( +1 )) ';' /; run; data _null_; infile trparms; input; put _infile_; run; data variables5bg; retain acs5yrvars "%varlist(acs.ustracts5yr)" ; acs5yrvars = upcase(acs5yrvars); set acs.variables5yr(keep=variable_name percent_variable wtvar univvar); * This messes up percentages in tables E5, S2, S3! ; * NoPercentVar= (univvar in ('CivLabForce','HHPop','Over16') or Variable_name='PovUniverseFamilyPop'); NoPercentVar = 0; if index(acs5yrvars, trim(upcase(variable_name))) then output; drop acs5yrvars; run; proc sql noprint; select percent_variable into :pctvarsbg separated by " " from variables5bg where (percent_variable ne ' ' and NoPercentVar=0) ; select univvar into :pctwtsbg separated by " " from variables5bg where (percent_variable ne ' ' and NoPercentVar=0) ; select variable_name into :meansbg separated by " " from variables5bg where wtvar ne ' ' ; select wtvar into :mwgtsbg separated by " " from variables5bg where wtvar ne ' ' ; select variable_name into :allVars separated by " " from variables5bg ; quit; data _null_; * This will trigger errors when we have variables not on dataset. ; set acs.usbgs5yr(keep= &pctvarsbg &meansbg &pctwtsbg &mwgtsbg); stop; run; * Generate the aggvarsparms&year.bg.sas file that will be used in CAPS ACS for BGs. ; filename bgparms "/pub/data/acs/Tools/aggvarparms&year.bg.sas"; data _null_; file bgparms linesize=132 flowover; put "* Generated by program in acs/Tools/&pgm..sas at &systime on &sysdate .; "; put '%let ACSMEANSBG=' %qwords(&meansbg, dlmtr=%str( +1 )) ';' /; put '%let ACSMWGTSBG=' %qwords(&mwgtsbg, dlmtr=%str( +1 )) ';' /; put '%let PCTVARSBG=' %qwords(&pctvarsbg, dlmtr=%str( +1 )) ';' /; put '%let PCTWTSBG=' %qwords(&pctwtsbg, dlmtr=%str( +1 )) ';' /; run; data _null_; infile bgparms; input; put _infile_; run; %put &allVars; %include sascode(notify);