x cd /pub/data/acs2005/Tools; %let pgm=cnvt_xtract; filename pgm "&pgm..sas"; *---Create the acs2005.xtract dataset with our standard extract from the 2005 base tables. Reads data from the btabs sub-directory collection and reads the variable defns from the invoke_dovars.sas module in this same directory. Most invoke_dovars coding by E. Cleveland. This module by J. Blodgett. ---*; %let year=2005; libname btabs "/pub/data/acs&year/basetabs"; libname ctabs "/pub/data/acs&year/basetabs"; libname acs "/pub/data/acs&year"; filename mrgstmt "merge_statement.sas"; *<----we used the metadata set to generate the merge statement to reference the base tables needed along with the relevant variables---; title "acs2005: &pgm"; /* =======================Begin comment================ %let dvmode=meta; data acs.Variables(label="Meta data describing the variables on ACS extract datasets"); attrib Name label='Variable Name' length=$32 Label length=$80 format=$char. Definition length=$200 label='Definition - Code used to derive' Comment length=$400 Format length=$16 TypeLen length=$8 label='Variable type and length' Universe length=$64 UnivVar length=$32 label='Universe Variable' WtVar length=$32 label='Weight Variable' Lvl length=3 label="Data Indent Level" Display length=3 label="Display in std report?" PctFlag length=3 label='Pct Variable Flag' Table length=$64 TableNo length=3 label='Table #' Keywords length=$80 Year length=$4 Source length=$40 RefTables length=$40 label='Related Table(s)' ; *** OtherYears label='Other Years Available' length=$32; retain Year '2005'; retain Source 'American Community Survey Base Tables, 2005 Data'; %include 'invoke_dovars.sas'/source2; run; proc print data=acs.variables; title2 'acs.variables'; run; ======================End comment================== */ *---------------Here we access the basetables metadata dataset in order to generate the code used to merge the appropriate base tables datasets and keep the appropriate table variables------------; %let tabs=%upcase( B01001 B02001 B03002 B05002 B05005 B05006 B07003 b08013 b08008 b09016 B10001 b11001 b11002 b12001 B12006 B08103 B15002 b17001 B17002 B17006 B17007 B17013 B17017 b18001 b18008 b19013 b21001 b23001 b19025 B19062 b19065 b19066 B19067 b19069 B10010 B19127 B19301 B20001 B20003 b25001 b25002 B25024 b25003 b25007 b25010 B25034 B25035 B25038 B25039 B25047 b25063 b25064 b25065 B25075 b25107 C06007 c07001 c08007 C08101 c08012 C14002 c17012 c17017 c17021 c18001 c18008 c19001 c24040 C24060 C25014 C25043 C25045 C25047 C25050 C25079 C10001 ); data tables; set acs.basetables ; where index("&tabs",trim(Table_ID)||' '); *--the table ID must be in the global list, followed by a blank---; run; proc sort; by table_set; run; data _null_; set tables end=_last; by table_set; file mrgstmt lrecl=132; if _n_=1 then put @1 "merge "; if first.table_set then put / @3 'acs.' table_set '(keep=_character_ '; put +1 table_ID +(-1) 'i:' @; if last.table_set then put ')' ; if _last then put ';'; run; %let dvmode=data; %let moe_default=0; data acs.xtract(label="Standard Extract for &year, all geographies" index=(geoid)); %include mrgstmt/source2; by geocomp geoid; ***where ((sumlev='010' or state='29') and geocomp='00') and sumlev in ('010','040','050'); %include 'invoke_dovars.sas'/source2; keep _character_ TotPop -- PctHvalOverMillion; *<===check this last variable value============; drop _: ; run; proc print data=acs.xtract; where state='29' and sumlev in ('040','050'); title2 'acs.xtract - MO state and counties only'; run;