x cd /pub/data/pl942010/Tools; %let pgm=raceids; filename pgm "&pgm..sas"; *--You can delete this line-; libname pl942010 '/pub/data/pl942010'; *-------Create and verify the pl942010.raceids "dimension table" with the 63 values of race_id and the corresponding info-; data race_ids(label='Table of Values for Multiple Race categories' ); length default=3; *--the numeric variables are short - no value is more than 1 digit long--; length race_id 3 RaceLabl $100 nraces 3; *--establishes variable order on dataset: these variables (the ids) are first-; do White=1,0; do Black=1,0; do Indian=1,0; do Asian=1,0; do HawnPI=1,0; do Other=1,0; *--assign the single race_id key using the race categories as binary digits--; race_id=white + 2* black + 4*indian + 8*asian + 16*hawnpi + 32*other; nraces=sum(of white--other); if nraces=0 then racelabl='No race (Totals)'; else racelabl=' '; if white then racelabl=trim(racelabl)||' White,'; if black then racelabl=trim(racelabl)||' Black,'; if indian then racelabl=trim(racelabl)||' American Indian & Alaska Native,'; if asian then racelabl=trim(racelabl)||' Asian,'; if hawnpi then racelabl=trim(racelabl)||' Native Hawaaian & Other Pac Islndr,'; if other then racelabl=trim(racelabl)||' Some other race'; RaceLabl=left(racelabl); _l=length(racelabl); if substr(racelabl,_l,1)=',' then substr(racelabl,_l)=' '; *--delete trailing comma-; output; end; end; end; end; end; end; drop _l; *---Note that each of the specific race variables - white, black, .. -- are 2-valued (0 and 1) indicating whether or not that race is included in the category. So the observation that has nraces=2, white=1,asian=1 and all other race variables=0 represents the dual-race category of White, Asian. ---; run; proc sort data=race_ids out=pl942010.race_ids (index=(race_id)); by race_id; run; proc print data=pl942010.race_ids; id race_id; title2 'The race_ids "Dimension Table"'; run; *-----Verify that we have used all 63 relevant elements of the input PL1 array exactly once and print report showing which race_id was assigned to each PL1 entry--------; data plxracid; set pl942010.race_ids; where nraces > 0; *--Omit the obs for total pop, i.e. for race_id=0---; *--This ptr array is identical to the one we use in the conversion step, below. For example, the 1st entry in the table PL1 (on the 1990 PL94-171 file as released by the Bureau) is Total Population and the 2nd entry is "Total Population of One Race". Neither of these correspond to our 63 specific racial categories, and as a result you do not see any entries of 1 or 2 in this table. The first entry in this table is 3. This means that a value of race_id=1 (white only) corresponds to the count in cell 3 of the PL1 table. The 2nd value in the table is 4 and means that a value of race_id=2 (black only) is in the 4th cell of the table. The 3rd value is 11, meaning that race-id=3 (black and white only) corresonds to the entry in cell 11 of table PL1 (i.e. in the field P0010011 if using the Bureau Data Dictionary). Etc. Note that Table PL1 has 71 entries and we point to only 63 of them. The other 8 cells in PL1 are the Total Population, the Total Population with exactly N races checked, where N ranges from 1 to 6, and a count of the Total Population with any 2 or more races checked. -----------------------------------------------*; array ptr(63) _temporary_ ( 3, 4,11, 5,12,16,27,6, 13,17,28,20,31,37,48,7, 14,18,29,21,32,38,49,23, 34,40,51,43,54,58,64,8, 15,19,30,22,33,39,50,24, 35,41,52,44,55,59,65,25, 36,42,53,45,56,60,66,46, 57,61,67,62,68,69,71); plx=ptr(race_id); label plx='PL1 index'; run ; proc sort data=plxracid; by plx; run ; *--Check to see if there are any duplicate plx codes and, if so, abort the step after flagging.--; data dups; set plxracid; by plx; if not (first.plx and last.plx); PUT _all_; abort abend; *----did NOT happen--; run ; proc print data=plxracid; by nraces notsorted; id nraces; var plx race_id racelabl white--other; title2 'Cross Reference Report Showing Relationship of Input PL1 Elements and race_id Codes'; run ;