/******************************************************************** This macro will read one or more county business pattern files in fixed-format txt file format such as was used for the 1998 and 1999 files stored on the Bureau web/FTP site. These files contain 6-digit NAICS codes, not the old 4-digit SIC codes. This macro will be invoked by conversion setups stored in the cpb/Tools program lib. John Blodgett, OSEDA, March, 2002. ********************************************************************/ /* Update history: 3-14-02: Basically starting over after a false start back in Sept. 2000 */ /********************************************************************/ /* BEGIN MACRO DEFINITION */ /********************************************************************/ %MACRO cbpcnvtn( revdate=14MAR02, /* *<=========Date of last revision======== */ files=us states counties, /* read and convert all 3 by default */ states=_all_, /* abbreviation for state(s) to be processed. */ /* default (_all_) says to do all states */ /* value is either _all__ or a list of state fips code. */ datadir=%str(/pub/data/cbp), /* path of input ascii files. Names of these files are as they are within the exe (zip) files provided by Census Bureau. */ unzip=0, /* input data is in the form of exe files that need to be accessed with a pipe that invokes unzip to access the txt files inside */ saslib=cbp, /* libref of output datasets. 2nd level names are determined by the macro. They are: ustotsyy, statesyy and ssyy (yy=&yr, ss=state abbrev.). The invoking program should have a libname cbp statement in it. */ yr=, /* REQUIRED. specifies 2-digit year of data */ obsin=9999999, /* # of input records to be processed */ obs=, /* alias for obsin */ debug=0); /* debug=1 triggers some extra output msgs */ %PUT %STR( ); %PUT ***************************************************************; %put * cbpcsvc macro Rev &revdate begin execution *; %put * Missouri State Census Data Center *; %PUT ***************************************************************; %PUT %STR( ); %if %quote(&obs) ne %str() %then %let obsin=&obs; %*--alias--; %let files=%lowcase(&files); %let states=%lowcase(&states); %if &states =_all_ %then %let states= %str(ak al ar az ca co ct dc de fl ga hi il ia id in ks ky la ma md me mi mo mn ms mt nc nd ne nh nj nm nv ny oh ok or pa ri sc sd tn tx ut va vt wa wi wv wy); /* %str(01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56); */ %if &debug %then %do; %put %str( ); %put; %put *****parameters specified*****; %put yr=&yr (year of data being converted); %put files= &files (types of files to be converted); %put states= &states (list of state files to be processed); %put saslib=&saslib (libref of output data set(s)); %put obsin=&obsin (# of input records to be processed); %put %str( ); %end; %if %length(&yr) ne 2 %then %do; %put ; %put ********parm year must be specified as 2-digit year of data******; %put %str( ) macro will abort and no processing will be done*****; %goto endmac; %end; %local cen year; %*--century, 4-digit year; %if %eval(&yr) gt 80 %then %let cen=19; %else %let cen=20; %let year=&cen&yr; /******************************** US File Processing ************************************/ %if %index(&files,us) %then %do; ********************************************; * convert u.s. totals file *; ********************************************; %if &unzip=0 %then %do; filename cbpus "&datadir/cbp&yr.us.txt" ; %end; %else %do; x cd &datadir; filename cbpus pipe "unzip -apq CBP&yr.US.EXE" ; %end; missing a b c e f g h i j k l m; data &saslib..ustots&yr.(label="U.S. totals for &year"); length naics $6 nlevel $1 Industry $6 SumLev $3; retain SumLev '010'; *<---Geographic Summary Level code, as used on CB Summary files--; infile cbpus lrecl=550; input usind $2. naics $6. tflag $1. @10 TotEmp 9. Q1Payroll 9. AnPayroll 10. Nestabs 8. @46 flag1_4 $1. Emp1_4 8. Wages1Q_1_4 8. WagesAn_1_4 9. Nestabs_1_4 7. @79 flag5_9 $1. Emp5_9 8. Wages1Q_5_9 8. WagesAn_5_9 9. Nestabs_5_9 7. @112 flag10_19 $1. Emp10_19 8. Wages1Q_10_19 8. WagesAn_10_19 9. Nestabs_10_19 7. @145 flag20_49 $1. Emp20_49 8. Wages1Q_20_49 9. WagesAn_20_49 9. Nestabs_20_49 6. @178 flag50_99 $1. Emp50_99 8. Wages1Q_50_99 9. WagesAn_50_99 9. Nestabs_50_99 6. @211 flag100_249 $1. Emp100_249 8. Wages1Q_100_249 9. WagesAn_100_249 9. Nestabs_100_249 6. @244 flag250_499 $1. Emp250_499 8. Wages1Q_250_499 8. WagesAn_250_499 9. Nestabs_250_499 6. @276 flag500_999 $1. Emp500_999 8. Wages1Q_500_999 8. WagesAn_500_999 9. Nestabs_500_999 5. @307 flag1000 $1. Emp1000 8. Wages1Q_1000 9. WagesAn_1000 9. Nestabs_1000 4. ; retain year "&year"; if _n_ gt &obsin then stop; /** Limit the number of observations **/ if usind ne '98' then do; put '*** wrong file ??? see hcopy data dict. *** '/ usind=/ _all_; stop; end; array _flag $1 flag1_4 flag5_9 flag10_19 flag20_49 flag50_99 flag100_249 flag250_499 flag500_999 flag1000; array _totemp emp1_4 emp5_9 emp10_19 emp20_49 emp50_99 emp100_249 emp250_499 emp500_999 emp1000; array Wages1Q Wages1Q_1_4 Wages1Q_5_9 Wages1Q_10_19 Wages1Q_20_49 Wages1Q_50_99 Wages1Q_100_249 Wages1Q_250_499 Wages1Q_500_999 Wages1Q_1000; array WagesAn WagesAn_1_4 WagesAn_5_9 WagesAn_10_19 WagesAn_20_49 WagesAn_50_99 WagesAn_100_249 WagesAn_250_499 WagesAn_500_999 WagesAn_1000; array nests Nestabs_1_4 Nestabs_5_9 Nestabs_10_19 Nestabs_20_49 Nestabs_50_99 Nestabs_100_249 Nestabs_250_499 Nestabs_500_999 Nestabs_1000; if naics='------' then industry=naics; else industry=compress(naics,'-/'); format industry $naics.; *--so internally they are similar, but industry prints as the name-; do over _flag; if _flag='D' then do; _totemp=.; Wages1Q=.; WagesAn=.; end; else if _flag=' ' then ; else put '*** Undetermined flag value *** ' _flag= / _all_; end; if naics='------' then nlevel=0; else do; nlevel= length( industry)-1; end; if tflag ne ' ' then do; q1payroll=.; anpayroll=.; IF TFLAG='A' THEN TOTEMP=.A; ELSE IF TFLAG='B' THEN TOTEMP=.B; ELSE IF TFLAG='C' THEN TOTEMP=.C; ELSE IF TFLAG='E' THEN TOTEMP=.E; ELSE IF TFLAG='F' THEN TOTEMP=.F; ELSE IF TFLAG='G' THEN TOTEMP=.G; ELSE IF TFLAG='H' THEN TOTEMP=.H; ELSE IF TFLAG='I' THEN TOTEMP=.I; ELSE IF TFLAG='J' THEN TOTEMP=.J; ELSE IF TFLAG='K' THEN TOTEMP=.K; ELSE IF TFLAG='L' THEN TOTEMP=.L; ELSE IF TFLAG='M' THEN TOTEMP=.M; else do; __nbf+1; drop __nbf; if __nbf le 12 then put '*** non-documented tflag value? *** ' tflag=; end; end; label nestabs='# of establishments: total' Nestabs_1_4='# of establishmeNestabs_ts: with 1-4 employees' Nestabs_5_9=': with 5-9 employees' Nestabs_10_19=': with 10-19 employees' Nestabs_20_49=': with 20-49 employees' Nestabs_50_99=': with 50-99 employees' Nestabs_100_249=': with 100-249 employees' Nestabs_250_499=': with 250-499 employees' Nestabs_500_999=': with 500-999 employees' Nestabs_1000=': with 1000+ employees' AnPayroll='Total Annual payroll ($1000)'; label WagesAn_1_4='Annual payroll($1000): with 1-4 empl.' WagesAn_5_9=': with 5-9 employees' WagesAn_10_19=': with 10-19 employees' WagesAn_20_49=': with 20-49 employees' WagesAn_50_99=': with 50-99 employees' WagesAn_100_249=': with 100-249 employees' WagesAn_250_499=': with 250-499 employees' WagesAn_500_999=': with 500-999 employees' WagesAn_1000=': with 1000+ employees' label naics ='NAICS industry code' nlevel='NAICS level'; label Q1Payroll='Total 1st Qtr payroll ($1000)' Wages1Q_1_4='Total 1st Qtr Payroll($1000): 1-4 empl. Size class' Wages1Q_5_9=': with 5-9 employees' Wages1Q_10_19=': with 10-19 employees' Wages1Q_20_49=': with 20-49 employees' Wages1Q_50_99=': with 50-99 employees' Wages1Q_100_249=': with 100-249 employees' Wages1Q_250_499=': with 250-499 employees' Wages1Q_500_999=': with 500-999 employees' Wages1Q_1000=': with 1000+ employees'; label TotEmp='Total mid-March employees' Emp1_4='Total mid-March employees: with 1-4 empl.' Emp5_9=': with 5-9 employees' Emp10_19=': with 10-19 employees' Emp20_49=': with 20-49 employees' Emp50_99=': with 50-99 employees' Emp100_249=': with 100-249 employees' Emp250_499=': with 250-499 employees' Emp500_999=': with 500-999 employees' Emp1000=': with 1000+ employees' ; drop usind tflag flag: ; run; %end; %*--us totals processing--; /******************************** US File Processing ENDS ************************************/ /******************************** STATE File Processing ************************************/ %if %index(&files,state) %then %do; *********************************************; * convert state totals file *; *********************************************; %if &unzip=0 %then %do; filename cbpst "&datadir/cbp&yr.st.txt" ; %end; %else %do; x cd &datadir; filename cbpst pipe "unzip -apq CBP&yr.ST.EXE" ; %end; missing a b c e f g h i j k l m; data &saslib..states&yr.(label="u.s. states data for &yr" compress=yes) ; length state stab $2 AreaName $20; length naics $6 nlevel $1 Industry $6 SumLev $3; retain SumLev '040'; infile cbpst lrecl=550; input state $2. @7 naics $6. @15 tflag $1. @16 TotEmp 11. Q1Payroll 11. AnPayroll 11. Nestabs 11. @60 flag1_4 $1. Emp1_4 11. Wages1Q_1_4 11. WagesAn_1_4 11. Nestabs_1_4 11. @105 flag5_9 $1. Emp5_9 11. Wages1Q_5_9 11. WagesAn_5_9 11. Nestabs_5_9 11. @150 flag10_19 $1. Emp10_19 11. Wages1Q_10_19 11. WagesAn_10_19 11. Nestabs_10_19 11. @195 flag20_49 $1. Emp20_49 11. Wages1Q_20_49 11. WagesAn_20_49 11. Nestabs_20_49 11. @240 flag50_99 $1. Emp50_99 11. Wages1Q_50_99 11. WagesAn_50_99 11. Nestabs_50_99 11. @285 flag100_249 $1. Emp100_249 11. Wages1Q_100_249 11. WagesAn_100_249 11. Nestabs_100_249 11. @330 flag250_499 $1. Emp250_499 11. Wages1Q_250_499 11. WagesAn_250_499 11. Nestabs_250_499 11. @375 flag500_999 $1. Emp500_999 11. Wages1Q_500_999 11. WagesAn_500_999 11. Nestabs_500_999 11. @420 flag1000 $1. Emp1000 11. Wages1Q_1000 11. WagesAn_1000 11. Nestabs_1000 11. @469 CenState $2.; stab=put(state,$fipstab.); AreaName=put(state,$state.); /**************************/ retain year "&year"; array _flag $1 flag1_4 flag5_9 flag10_19 flag20_49 flag50_99 flag100_249 flag250_499 flag500_999 flag1000; array _totemp emp1_4 emp5_9 emp10_19 emp20_49 emp50_99 emp100_249 emp250_499 emp500_999 emp1000; array Wages1Q Wages1Q_1_4 Wages1Q_5_9 Wages1Q_10_19 Wages1Q_20_49 Wages1Q_50_99 Wages1Q_100_249 Wages1Q_250_499 Wages1Q_500_999 Wages1Q_1000; array WagesAn WagesAn_1_4 WagesAn_5_9 WagesAn_10_19 WagesAn_20_49 WagesAn_50_99 WagesAn_100_249 WagesAn_250_499 WagesAn_500_999 WagesAn_1000; array nests Nestabs_1_4 Nestabs_5_9 Nestabs_10_19 Nestabs_20_49 Nestabs_50_99 Nestabs_100_249 Nestabs_250_499 Nestabs_500_999 Nestabs_1000; if _n_ gt &obsin then stop; /** Limit the number of observations **/ if naics='------' then industry=naics; else industry=compress(naics,'-/'); format industry $naics.; *--so internally they are similar, but industry prints as the name-; do over _flag; if _flag='D' then do; _totemp=.; Wages1Q=.; WagesAn=.; end; else if _flag=' ' then ; else put '*** Undetermined flag value *** ' _flag= / _all_; end; if naics='------' then nlevel=0; else do; nlevel= length( industry)-1; end; if tflag ne ' ' then do; q1payroll=.; anpayroll=.; IF TFLAG='A' THEN TOTEMP=.A; ELSE IF TFLAG='B' THEN TOTEMP=.B; ELSE IF TFLAG='C' THEN TOTEMP=.C; ELSE IF TFLAG='E' THEN TOTEMP=.E; ELSE IF TFLAG='F' THEN TOTEMP=.F; ELSE IF TFLAG='G' THEN TOTEMP=.G; ELSE IF TFLAG='H' THEN TOTEMP=.H; ELSE IF TFLAG='I' THEN TOTEMP=.I; ELSE IF TFLAG='J' THEN TOTEMP=.J; ELSE IF TFLAG='K' THEN TOTEMP=.K; ELSE IF TFLAG='L' THEN TOTEMP=.L; ELSE IF TFLAG='M' THEN TOTEMP=.M; else do; __nbf+1; drop __nbf; if __nbf le 12 then put '*** non-documented tflag value? *** ' tflag=; end; end; label nestabs='# of establishments: total' Nestabs_1_4='# of establishmeNestabs_ts: with 1-4 employees' Nestabs_5_9=': with 5-9 employees' Nestabs_10_19=': with 10-19 employees' Nestabs_20_49=': with 20-49 employees' Nestabs_50_99=': with 50-99 employees' Nestabs_100_249=': with 100-249 employees' Nestabs_250_499=': with 250-499 employees' Nestabs_500_999=': with 500-999 employees' Nestabs_1000=': with 1000+ employees' AnPayroll='Total Annual payroll ($1000)'; label WagesAn_1_4='Annual payroll($1000): with 1-4 empl.' WagesAn_5_9=': with 5-9 employees' WagesAn_10_19=': with 10-19 employees' WagesAn_20_49=': with 20-49 employees' WagesAn_50_99=': with 50-99 employees' WagesAn_100_249=': with 100-249 employees' WagesAn_250_499=': with 250-499 employees' WagesAn_500_999=': with 500-999 employees' WagesAn_1000=': with 1000+ employees' label naics ='NAICS industry code' nlevel='NAICS level'; label Q1Payroll='Total 1st Qtr payroll ($1000)' Wages1Q_1_4='Total 1st Qtr Payroll($1000): 1-4 empl. Size class' Wages1Q_5_9=': with 5-9 employees' Wages1Q_10_19=': with 10-19 employees' Wages1Q_20_49=': with 20-49 employees' Wages1Q_50_99=': with 50-99 employees' Wages1Q_100_249=': with 100-249 employees' Wages1Q_250_499=': with 250-499 employees' Wages1Q_500_999=': with 500-999 employees' Wages1Q_1000=': with 1000+ employees'; label TotEmp='Total mid-March employees' Emp1_4='Total mid-March employees: with 1-4 empl.' Emp5_9=': with 5-9 employees' Emp10_19=': with 10-19 employees' Emp20_49=': with 20-49 employees' Emp50_99=': with 50-99 employees' Emp100_249=': with 100-249 employees' Emp250_499=': with 250-499 employees' Emp500_999=': with 500-999 employees' Emp1000=': with 1000+ employees' ; drop tflag flag: ; /*************************/ run; %end; /******************************** STATE File Processing ENDS ************************************/ /******************************** COUNTY File Processing ************************************/ %if %index(&files,counties) %then %do; **********************************************; * convert County totals file *; **********************************************; %libname(sf12000,xxgeos); %if &unzip=0 %then %do; filename cbpco "&datadir/cbp&yr.co.txt" ; %end; %else %do; x cd &datadir; filename cbpco pipe "unzip -apq CBP&yr.CO.EXE" ; %end; missing a b c e f g h i j k l m; data temp; length County $5; format county $county.; length mtype $1; label mtype='metro type'; length state stab $2; length fipco $5; length naics $6 nlevel $1 Industry $6 SumLev $3; retain SumLev '050'; infile cbpco lrecl=550; input state $2. fips $3. @7 naics $6. @14 tflag $1. @15 TotEmp 12. Q1Payroll 12. AnPayroll 12. Nestabs 6. @57 Nestabs_1_4 6. Nestabs_5_9 6. Nestabs_10_19 6. Nestabs_20_49 6. @81 Nestabs_50_99 6. Nestabs_100_249 6. Nestabs_250_499 6. Nestabs_500_999 6. @105 Nestabs_1000 6. Nestabs_1000_1499 6. Nestabs_1500_2499 6. Nestabs_2500_4999 6. @129 Nestabs_5000 6. @137 CenState $2.; stab=put(state,$fipstab.); fipco=trim(state)||trim(fips); County = fipco; /**************************/ retain year "&year"; if _n_ gt &obsin then stop; /** Limit the number of observations **/ if state ne '29' then ; if naics='------' then industry=naics; else industry=compress(naics,'-/'); format industry $naics.; *--so internally they are similar, but industry prints as the name-; if naics='------' then nlevel=0; else do; nlevel= length( industry)-1; end; if tflag ne ' ' then do; q1payroll=.; anpayroll=.; IF TFLAG='A' THEN TOTEMP=.A; ELSE IF TFLAG='B' THEN TOTEMP=.B; ELSE IF TFLAG='C' THEN TOTEMP=.C; ELSE IF TFLAG='E' THEN TOTEMP=.E; ELSE IF TFLAG='F' THEN TOTEMP=.F; ELSE IF TFLAG='G' THEN TOTEMP=.G; ELSE IF TFLAG='H' THEN TOTEMP=.H; ELSE IF TFLAG='I' THEN TOTEMP=.I; ELSE IF TFLAG='J' THEN TOTEMP=.J; ELSE IF TFLAG='K' THEN TOTEMP=.K; ELSE IF TFLAG='L' THEN TOTEMP=.L; ELSE IF TFLAG='M' THEN TOTEMP=.M; else do; __nbf+1; drop __nbf; if __nbf le 12 then put '*** non-documented tflag value? *** ' tflag=; end; end; label nestabs='# of establishments: total' Nestabs_1_4='# of establishmeNestabs_ts: with 1-4 employees' Nestabs_5_9=': with 5-9 employees' Nestabs_10_19=': with 10-19 employees' Nestabs_20_49=': with 20-49 employees' Nestabs_50_99=': with 50-99 employees' Nestabs_100_249=': with 100-249 employees' Nestabs_250_499=': with 250-499 employees' Nestabs_500_999=': with 500-999 employees' Nestabs_1000=': with 1000+ employees' Nestabs_1000_1499=': with 1000-1499 employees' Nestabs_1500_2499=': with 1500-2499 employees' Nestabs_2500_4999=': with 2500-4999 employees' Nestabs_5000=': with 5000+ employees' ; label naics ='NAICS industry code' nlevel='NAICS level'; label TotEmp='Total mid-March employees' Q1Payroll='Total 1st Qtr payroll ($1000)' AnPayroll='Total Annual payroll ($1000)'; drop tflag ; run; proc sort data=temp; by county; run; data temp1; set xxgeos.uscntys(keep = county Region Division MSACMSA PMSA NECMA ); format county $county.; run; data &saslib..uscos&yr.(label="County totals for US, &yr" compress=yes); merge temp1 temp ; by county; if NECMA not in ('9999','####') then mtype='N'; else if PMSA not in ('9999','####') then mtype='P'; else if MSACMSA not in ('9999','####') then mtype='M'; run; proc sort data=&saslib..uscos&yr (index = (state) ); by county naics; run; %end; /******************************** COUNTY File Processing ENDS ************************************/ %endmac: %mend cbpcnvtn;