x cd /pub/data/eeo2000/Tools; %let pgm=cnvttbls; filename pgm "&pgm..sas"; /*----We read the SAS datasets created by the Census Bureau and convert them to our standards (mostly variable name changes). NOTE: This setup assumes that the eeo2kfmts.sas job was run so that we can access those permanent format codes in the a formats catalog. (The library containing the formats catalog is assumed to be set up for automatic access using an autoexec or a config file.) jgb, 12-03. IMPORTANT NOTES: 1. Some of the conversion invocations here may be commented out because they have already run. If you are importing this code to run at your site you will need to un-comment those steps. 2. The setup in eeo2kfmts.sas in this same program directory defines a number of geographic and other format codes that associate names with codes. Those format codes are referenced in this setup and any time someone accesses these datasets it is assumed that those format codes are accessible. So you need to know how to create a permanent formats catalog and to make it accessible. The easiest way is to include a "libname library ;" statement that points to the directory containing the formats catalog. That same statement should be added to the eeo2kfmts.sas setup. ----*/ title "EEO 2000 Table Conversion Run (&pgm..sas)"; libname eeo2000 '/pub/data/eeo2000'; %macro dotable(tno, /* table number (1 thru 24) */ label, /* dataset label to briefly describe table */ occvar, /* variable containing occupation code, if any. Must specify a value of none if there is no such var. */ socode=1, /* Set to 0 if there is no soc occupation code. Will be set to 0 if occvar=none */ geolen=7, /* length of the geocode variable. Value of 0 indicates no such var (and no Sumlevel either). Ignored if flowfile=1 */ ncells=24, /* number of cells in the table. We rename variable t&tno.cell&i, where &i ranges from 1 to &ncells */ flowfile=0, /* set to true (1) if this is a file with Worksite / Residence (work flow) summaries */ dimvars=, /* Dimension variables that define the table cells, specified in order */ dimlens=, /* List of variable length values to correspond to dimvars */ state=1, /* Set to 0 if state is not a variable on the file */ county=0, /* set to 1 if county is a variable on the file (it will be renamed on input and made a 5-character fips code on output) */ csarea=0, /* Set to 1 if file has summaries by county set areas */ place=, /* Set to fips or census if it occurs on the file, the 2 values indicating if it is the fips or census version. If it is a census code we will attempt to generate a FIPS version as well. */ metro=0, /* Set to 1 if set has summaries for metro areas. Metro becomes msapmsa. */ substate=29mo, /* Specifies a state for which special subset views are to be created based on the value of the state code. Value consisets of 2-digit fips code followed by 2-digit postal abbreviation. Default is for Missouri. Specifying a value of 06ca would work for California. Set to null to indicate no such views should be generated. */ where=, /* specify a filter to be applied after the set statement. Do not use the word where or include a semicolon but otherwise code it like a where statement. E.g. a value of "total ge 100" would select only cases where the total employees in the occupation category was at least 100. */ setout=, /* leave null to have name assigned as ustable&tno. Allows you to override this default */ skipcnvt=0, /* specify skipcnvt to skip the convert step and go to the view and index generating steps */ compress=yes,/* specify no if output set is not to be compressed */ nprint=10, /* # of sample observations to proc print after convert */ debug=0); %local stab stfips i geosfx work; %put Converting Table &tno ****** ; %local occvarln; %if &occvar=cenocc %then %let occvarln=3; %else %if &occvar=opm %then %let occvarln=3; %else %if &occvar=eeo or &occvar=eeo_1 or &occvar=st_loc %then %let occvarln=2; %else %if &occvar=none %then %let socode=0; %else %do; data _null_; error "****Value of macro parm occvar (&occvar) not recognized. Convert run aborting. ***"; *--in foreground just stop the step. In batch, abort the run.---; if "&sysenv"="FORE" then stop; else abort; run; %end; %if &occvar=st_loc or &occvar=eeo or &occvar=eeo_1 %then %let socode=0; %if &skipcnvt %then %goto aftcnvt; %if %superq(setout) eq %str() %then %let setout=ustable&tno; %if &flowfile=1 %then %do; %let socode=0; %let ncells=0; %let state=0; %if &tno le 13 %then %let geosfx=cty; %else %let geosfx=pl; %let compress=no; %*--compressing makes this files bigger!--; %end; %else %if &tno ge 20 %then %let work=work; %else %let work=; data eeo2000.&setout (label="Table &tno: &label" compress=&compress %if &state %then %str( index=(&work.state) ); ); *--declare ID variables so they go first -- before the set statement--; %if &tno=20 %then %do; retain SumLev '010'; %end; %if &flowfile=0 and &geolen ne 0 %then %do; %*--the $eeogeo "hybrid format" code is defined in the eeo2kfmts.sas module.--; length SumLev $3 GeoCode GeoName $&geolen; format GeoName $eeogeo64.; %end; %if &state %then %do; length &work.State $2; %end; %if &county %then %do; length &work.county $5; *<--we make it a 5-char code instead of 3--; %end; %if &csarea %then %do; length &work.csarea $7; %end; %if &place=1 %then %let place=fips; %if &place=fips %then %do; length &work.place $5; %end; %else %if &place=census %then %do; length &work.placece $4 ; %end; %if &metro %then %do; length msapmsa $4; %end; %if &occvar ne none %then %do; length &occvar OccName $&occvarln; %*--Occname is just a copy of the occupation code variable with a custom format assigned that causes it to display the meaning of the code rather than the code itself---; format Occname $ %if &occvar=cenocc %then cenocc.; %else %if &occvar=opm %then opmocc.; %else %if &occvar=st_loc %then stloc.; %else %if &occvar=eeo %then eeofmt.; %else %if &occvar=eeo_1 %then eeo1fm.; ; %end; %if &socode %then %do; length socode $7; %end; set eeo2000.table&tno (rename=( %if &flowfile=0 and &geolen ne 0 %then %do; sumlevel=SumLev %end; %if &place=census %then %do; &work.place=&work.placece %end; %if &metro %then %do; metro=msapmsa %end; %if &county %then %do; &work.county=_cnty %end; )); %if %superq(where) ne %str() %then %do; where %unquote(&where) ; %end; %if &flowfile=0 and &geolen ne 0 %then %do; GeoName=geocode; *<---but we associated the format code $eeogeo with it so it will come out as a name-; %end; %if &occvar ne none %then %do; OccName=&occvar; %end; %if &county %then %do; &work.County=&work.State||_cnty; format &work.county $county.; %end; %if &ncells %then %do; rename %do i=1 %TO &ncells; t&tno.cell&i=t&tno.i&i %end; ; %*--we rename, for example, t1cell13 to t1i13, our standard table-cell naming convention--; %end; retain __dum 0; drop _: ; run; %aftcnvt: %if &nprint %then %do; proc print data=eeo2000.ustable&tno(obs=&nprint); title2 "eeo2000.ustable&tno"; run; %end; %*---if specified we create a state-based subset view---; %if (&state or &flowfile) and %superq(substate) ne %str() %then %do; %let stab=%substr(&substate,3,2); %let stfips=%substr(&substate,1,2); proc sql; create view eeo2000.&stab.table&tno as select * from ustable&tno %if &flowfile=0 %then %do; where &work.state="&stfips"; %end; %else %do; where substr(pow_geo_&geosfx,1,2) ="&stfips" or substr(res_geo_&geosfx,1,2) ="&stfips"; %end; quit; %end; %*----Create indices by sumlev and sumlev/geocode if appropriate--; %if &flowfile=0 and &geolen ne 0 %then %do; proc datasets library=eeo2000 nolist; modify ustable&tno; index create SumLev; index create SLGeo=(SumLev geocode); quit; %end; %mend dotable; options mprint; /*<=========================Comment out===================================== *---Residence geography tables-------*; %dotable(1,%str(Detailed Census Occupations by Race/Ethnicity and Sex), csarea=1,metro=1, occvar=cenocc); %dotable(2,%str(Detailed OPM Occupation Groups by Race/Ethnicity and Sex), csarea=1,metro=1, occvar=opm); *---Tables 3 and 4 not available yet---*; %dotable(5,%str(State & local job categories by Race/Ethnicity and Sex), csarea=0,metro=1,county=1,place=1, occvar=st_loc); %dotable(6,%str(Race/Ethnicity, Younger Age Groups & Educ. Attainment(4): Counties & Places 50k+), csarea=0,metro=0,occvar=none, county=1,place=1,ncells=480) %dotable(7,%str(Race/Ethnicity, Younger Age Groups & Educ. Attainment(6): US, States & Metros), csarea=0,metro=1,occvar=none, county=0,place=0,ncells=576) options mprint; *------Work Flow Tables------------*; %dotable(8,%str(County to county (some) workflows, Detailed Census Occs by Race/Ethnicity and Sex), flowfile=1,occvar=cenocc,skipcnvt=0) %dotable(9,%str(County to county (some) workflows, Detailed OPM Occs by Race/Ethnicity and Sex), flowfile=1,occvar=opm) %dotable(12,%str(County to county (some) workflows, St + Local Govt Job Cats by Race/Ethnicity and Sex), flowfile=1,occvar=st_loc) %dotable(13,%str(County to county (some) workflows, Younger age grps(4) by Education(5) by Race/Ethnicity and Sex), flowfile=1,occvar=none) %dotable(14,%str(Place/County workflows, Detailed census occs by Race/Ethnicity and Sex), flowfile=1,occvar=cenocc) %dotable(15,%str(Place/County workflows, Detailed OPM occs by Race/Ethnicity and Sex), flowfile=1,occvar=opm) %dotable(18,%str(Place/County workflows, St + Local Govt Job Cats by Race/Ethnicity and Sex), flowfile=1,occvar=st_loc) %dotable(19,%str(Place/County workflows, Younger age grps(4) by Education(5) by Race/Ethnicity and Sex), flowfile=1,occvar=none) *---Worksite geography tables-------*; %dotable(20,%str(U.S. Detailed Census Occupations by Education(6), Race/Ethnicity and Sex),State=0,geolen=0, occvar=cenocc,ncells=144,substate=); ===========================End commented out================================ */ %dotable(21,%str(Large cos & places, Detailed Census Occupations by Education(5), Race/Ethnicity and Sex), occvar=cenocc,place=census,geolen=6,state=1,county=1,ncells=120); %dotable(22,%str(US + Large cos & places, Detailed Census Occupations by older age groups(4), Race/Ethnicity and Sex), occvar=cenocc,place=census,geolen=6,state=1,county=1,ncells=96); %*---We do not convert table23. It is too inefficient with all its 0 cells. We shall attempt an alternate view where the industry is made a class variable (instead of a dimension of the data table) and non-zero cells are not saved. See altviews.sas setup. --; %dotable(24,%str(US + Large cos & places, Detailed Census Occupations by Earnings(8), Race/Ethnicity and Sex), occvar=cenocc,place=census,geolen=6,state=1,county=1,ncells=192); /*<=========================Comment out===================================== *---The later 6 tables, all with EEO occupation groups---*; %dotable(3,%str(EEO 14 Occupation Groups by Race/Ethnicity and Sex), csarea=0,metro=1,county=1,place=1, occvar=eeo); %dotable(4,%str(EEO 9 Occupation Groups by Race/Ethnicity and Sex), csarea=0,metro=1,county=1,place=1, occvar=eeo_1); %dotable(10,%str(County to county (some) workflows, 14 EEO Occs by Race/Ethnicity and Sex), flowfile=1,occvar=eeo) %dotable(11,%str(County to county (some) workflows, 9 EEO Occs by Race/Ethnicity and Sex), flowfile=1,occvar=eeo_1) %dotable(16,%str(Place/County workflows, 14 EEO occs by Race/Ethnicity and Sex), flowfile=1,occvar=eeo) %dotable(17,%str(Place/County workflows, 9 EEO occs by Race/Ethnicity and Sex), flowfile=1,occvar=eeo_1) ===========================End commented out================================ */ %include sascode(notify);