x cd /pub/data/acs2005/Tools; %let pgm=read_profiles; filename pgm "&pgm..sas"; *----Read the ACS profile tables (demographic, social, economic and housing). John Blodgett, OSEDA as part of Missouri Census Data Center contract. Aug, 2006. (orignally) Some of this code was adapted from a program written by Dan Keating, Washington Post. Rev. 8/15/2006 4:12PM Modifying to run with new data and metadata, incl the housing profile. 1/07. Ran setup in P:\mcdc\acsdocs\read_profile_shells2005.sas (uploaded to Tools lib here) which creates the acs.profilevars dataset. That setup reads p:\mcdc\acsdocs\prof_stubs.xls . For this run we changed all occurrences of table_id to tableid. Running 5-2-07 with addition of code to cause all the non-MOE variables to come first on the datasets. ----*; %let year=2005; %let rawdata=%str(/pub/data/acs&year/rawdata); libname acs&year "/pub/data/acs&year"; libname acs (acs&year); *<---create alias name---; libname profiles "/pub/data/acs&year/profiles"; filename proftabs "&rawdata/Wave1,2,3Profiles.txt"; *<====just has metadata re profiles. EDITED by us to replace tabs with equivalent blank spaces.--; *---define the macro that will read one table file, creating a corr sas dataset-----*; %global nlines setlabel; %macro dopro(table, /* profile table id value. Will be lower-cased for unix. */ setout=, /* output sas dataset. Will default to profiles.&table */ debug=0); %let table=%lowcase(&table); %*--assign default value for setout----; %if %nrbquote(&setout) eq %str() %then %let setout=profiles.&table; %let nlines=; %let setlabel=; *--following data step will define these via symput --; data _null_; infile proftabs end=last firstobs=2 truncover; *<--metadata file with names, titles and sizes of profiles-; input tableid $8. nlines 3. +3 table_title $60.; tableid=lowcase(compress(tableid,'0-')); *--remove the 0s and the dash and lower-case--; if tableid="&table"; call symput('nlines',left(put(nlines,4.))); call symput('setlabel',trim(table_title)); put 'Processing table ' tableid table_title nlines=; stop; run; %put _global_; *----Here we edit labels in the profilevars metadata set to add the '% Poor' info to items in table dp3--; data acs.profilevars; set acs.profilevars_original; if tableid="dp3" and Line_number ge 94 then VarLabel=trim(VarLabel)||' - % Poor'; run; *---This step reads the metadata (profilevars) step and creates the "table" of global variables with variable label vals-; data _null_; set acs.profilevars end=last; where tableid="&table" ; *--this step generates the variable labels for the tables in a series of global macro variables named varlabel1 thru varlabel&nlines. Verification takes place to make sure things jive. ----; length global_varname $24; global_varname="varlabel"||left(put(line_number,4.)); varlabel=translate(varlabel,"'",'"'); *--replace double quotes with single quotes in labels--; call symput(trim(global_varname),trim(varlabel)); if last then do; if line_number ne &nlines then do; file log; error "***logic problem*** Value of line_number on last entry for table does not match nlines global value (&nlines) **** "/ "nlines=&nlines " line_number=; abort abend; end; end; run; %put _global_; *<================================temp diagnostic to make sure we defined the globals as expected---; filename in "&rawdata/prof.txt"; *<====this is the huge data file====; *------------------Here is the step that actually reads the data file and creates the profiles dataset---------; data &setout (label="&setlabel" index=(geoid)); infile in lrecl=4096 truncover; missing N; length geoid $20 sumlev $3 State $2 Geocomp $2 Geocode $12 _tableck $12 _margin $20 default=5; input _tableck $ geoid $ @; if lowcase(compress(_tableck,'0-')) = "&table"; set acs.geography(keep=geoid -- State) key=geoid; *<---see geography.sas for creation---; if _iorc_ then do; put / '***Geography key read failed for ' geoid= ' -- Observation deleted.' ; list; _nbadgeo+1; if _nbadgeo ge 20 then abort abend; delete; end; %*--This loop is the hard part---; *---generate retain statement that causes all the actual data vars to be first on the dataset followed by the marg vars.-; retain &table.i1 - &table.i&nlines ; %do j=1 %to &nlines; %*--we process the jth line of the table, creating up to 3 vars for each. The item var, the margin var and, sometimes, the pct var.---; %let vname=&table.i&j ; %let mname=Marg&table.i&j; label &vname="&&varlabel&j" ; input &vname _margin @; length &mname 5; if _margin=:'***' then &mname=.; else &mname =compress(substr(_margin,4),','); %*<--edit to remove "+/-" and commas. Convert to numeric-; %end; drop _:; run; %mend dopro; options mprint; %*dopro(dp1); options NOmprint; %dopro(dp2); %dopro(dp2pr); %dopro(dp3); %dopro(dp4); %content(profiles.dp3,directory=1) ; *---delete this line outside the mcdc environment--------;