/******************************************************************** This macro will read one or more county business pattern files in CSV (comma-delimited) files format such as was used for the 2005 files stored on the Bureau web site. (http://www.census.gov/epcd/cbp/download/dwncbp05.html on 6-4-07, for example) . 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 cbp/Tools program lib. John Blodgett, OSEDA, June, 2007. ********************************************************************/ /* Update history: 6-04-07: Changing the default for datadir parm to point to zipfiles. Starting with this year we shall be downloading the files from the Bureau web site instead of uploading from the cd-rom. 6-06-07: Adding code to reference $naics02_ format code starting with data for 2002. Also adding length statement to shorten nestabs variables. Fixing label on 1st nestabs variable. Making the states data set compressed. Associating the variable totemp with the format code cbpemp. so that these suppressed values will display as the appropriate intervals. We also added code to merge CBSA geocodes from our most recent georef.cbsacos dataset. ($naics02_ did not work so we changed it to $naics2_, 6-28-08, jgb) $naics2_ "worked", but that was the wrong code. Should have been $naics02_ (4-21-09) 1-19-08: Added code to process the cbpmsa zip files with cbsa metro area summaries. 6-28-08: Change $naics02_ to $naics2_ . */ /********************************************************************/ /* BEGIN MACRO DEFINITION */ /********************************************************************/ %MACRO cbpcnvt( revdate=01/19/2008, /* *<=========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/zipfiles), /* path of input files. Starting circa 2007 we get these as .zip files downloaded from the Bureau web site. */ unzip=1, /* input data is in the form of .zip files that need to be accessed with a pipe that invokes unzip to access the txt (comma-delimited) 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 * cbpcnvt 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 &yr= %str() %then %let yr=%substr(&year,3,2); %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; %local dsd; %*--assign value of null or dsd depending on wether we want to declare input as a CSV file; %if &year gt 2000 %then %let dsd=dsd; %else %let dsd=%str(); %*---Problem using the name $naics02_ for format code: it gets truncated and becomes $naics02 which is invalid because it ends with a number. So need to change it to $naics2_ (6-08, jgb)---; %if &year le 2002 %then %let naicsfmt=naics; %else %let naicsfmt=naics02_; %*--naics02_ starting with 03 data; %if %superq(datadir) = %str() %then %do; %if &year le 2004 %then %let datadir=%str(/pub/data/cbp/exefiles); %else %let datadir=%str(/pub/data/cbp/zipfiles); %end; %local compfiletype; %if %index(&datadir,exefiles) %then %let compfiletype=exe; %else %let compfiletype=zip; %if &debug %then %put _all_; /******************************** 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 -pqa cbp&yr.us.&compfiletype." ; %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 %if &year gt 2000 %then %str(dsd firstobs=2 delimiter='2C0D'x);; %if &yr=99 %then %do; 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. ; %end; %else %if (&yr=00) %then %do; 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 9. WagesAn_1_4 9. Nestabs_1_4 7. @80 flag5_9 $1. Emp5_9 8. Wages1Q_5_9 9. WagesAn_5_9 9. Nestabs_5_9 7. @114 flag10_19 $1. Emp10_19 8. Wages1Q_10_19 9. WagesAn_10_19 9. Nestabs_10_19 7. @148 flag20_49 $1. Emp20_49 8. Wages1Q_20_49 9. WagesAn_20_49 9. Nestabs_20_49 6. @181 flag50_99 $1. Emp50_99 8. Wages1Q_50_99 9. WagesAn_50_99 9. Nestabs_50_99 6. @214 flag100_249 $1. Emp100_249 8. Wages1Q_100_249 9. WagesAn_100_249 9. Nestabs_100_249 6. @247 flag250_499 $1. Emp250_499 8. Wages1Q_250_499 9. WagesAn_250_499 9. Nestabs_250_499 6. @280 flag500_999 $1. Emp500_999 8. Wages1Q_500_999 9. WagesAn_500_999 9. Nestabs_500_999 5. @312 flag1000 $1. Emp1000 8. Wages1Q_1000 9. WagesAn_1000 9. Nestabs_1000 4. ; %end; %else %do; input usind :$2. naics :$6. tflag :$1. TotEmp Q1Payroll AnPayroll Nestabs flag1_4 :$1. Emp1_4 Wages1Q_1_4 WagesAn_1_4 Nestabs_1_4 flag5_9 :$1. Emp5_9 Wages1Q_5_9 WagesAn_5_9 Nestabs_5_9 flag10_19 :$1. Emp10_19 Wages1Q_10_19 WagesAn_10_19 Nestabs_10_19 flag20_49 :$1. Emp20_49 Wages1Q_20_49 WagesAn_20_49 Nestabs_20_49 flag50_99 :$1. Emp50_99 Wages1Q_50_99 WagesAn_50_99 Nestabs_50_99 flag100_249 :$1. Emp100_249 Wages1Q_100_249 WagesAn_100_249 Nestabs_100_249 flag250_499 :$1. Emp250_499 Wages1Q_250_499 WagesAn_250_499 Nestabs_250_499 flag500_999 :$1. Emp500_999 Wages1Q_500_999 WagesAn_500_999 Nestabs_500_999 flag1000 :$1. Emp1000 Wages1Q_1000 WagesAn_1000 Nestabs_1000 ; %end; if _n_=1 then list; 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 $&naicsfmt.. ; *--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 establishments: 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: ; length nestabs: 5; format totemp cbpemp.; 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.&compfiletype." ; %end; missing a b c e f g h i j k l m; data states&yr; ***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 %if &year gt 2000 %then %str(dsd firstobs=2 delimiter='2C0D'x);; input %if &yr=99 %then %do; 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.; %end; %else %if &yr=00 %then %do; state $2. @7 naics $6. @15 tflag $1. @16 TotEmp 9. Q1Payroll 10. AnPayroll 10. Nestabs 7. @52 flag1_4 $1. Emp1_4 7. Wages1Q_1_4 8. WagesAn_1_4 9. Nestabs_1_4 7. @84 flag5_9 $1. Emp5_9 7. Wages1Q_5_9 8. WagesAn_5_9 9. Nestabs_5_9 7. @116 flag10_19 $1. Emp10_19 8. Wages1Q_10_19 8. WagesAn_10_19 9. Nestabs_10_19 7. @149 flag20_49 $1. Emp20_49 8. Wages1Q_20_49 9. WagesAn_20_49 9. Nestabs_20_49 6. @182 flag50_99 $1. Emp50_99 8. Wages1Q_50_99 9. WagesAn_50_99 9. Nestabs_50_99 6. @215 flag100_249 $1. Emp100_249 8. Wages1Q_100_249 9. WagesAn_100_249 9. Nestabs_100_249 6. @248 flag250_499 $1. Emp250_499 8. Wages1Q_250_499 8. WagesAn_250_499 9. Nestabs_250_499 5. @279 flag500_999 $1. Emp500_999 8. Wages1Q_500_999 9. WagesAn_500_999 9. Nestabs_500_999 5. @311 flag1000 $1. Emp1000 8. Wages1Q_1000 9. WagesAn_1000 9. Nestabs_1000 5. @347 CenState $2.; %end; %else %do; state :$2. naics :$6. tflag :$1. TotEmp Q1Payroll AnPayroll Nestabs flag1_4 :$1. Emp1_4 Wages1Q_1_4 WagesAn_1_4 Nestabs_1_4 flag5_9 :$1. Emp5_9 Wages1Q_5_9 WagesAn_5_9 Nestabs_5_9 flag10_19 :$1. Emp10_19 Wages1Q_10_19 WagesAn_10_19 Nestabs_10_19 flag20_49 :$1. Emp20_49 Wages1Q_20_49 WagesAn_20_49 Nestabs_20_49 flag50_99 :$1. Emp50_99 Wages1Q_50_99 WagesAn_50_99 Nestabs_50_99 flag100_249 :$1. Emp100_249 Wages1Q_100_249 WagesAn_100_249 Nestabs_100_249 flag250_499 :$1. Emp250_499 Wages1Q_250_499 WagesAn_250_499 Nestabs_250_499 flag500_999 :$1. Emp500_999 Wages1Q_500_999 WagesAn_500_999 Nestabs_500_999 flag1000 :$1. Emp1000 Wages1Q_1000 WagesAn_1000 Nestabs_1000 CenState :$2.; %end; 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 $&naicsfmt..; *--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 establishments: 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: ; length nestabs: 4; format totemp cbpemp.; run; proc sort data=states&yr out= &saslib..states&yr.(label="u.s. states data for &yr" compress=yes index=(state) ); by state; *---it comes sorted by census state (censtat)---; run; %end; /******************************** STATE File Processing ENDS ************************************/ /******************************** COUNTY File Processing ************************************/ %if %index(&files,counties) %then %do; **********************************************; * convert County totals file *; **********************************************; %libname(sf12000,xxgeos); libname georef '/pub/data/georef' access=readonly; %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.&compfiletype." ; %end; missing a b c e f g h i j k l m; data temp&yr; 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 %if &year gt 2000 %then %str(dsd firstobs=2 delimiter='2C0D'x);; %if %superq(dsd) eq %str() %then %do; 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.; %end; %else %do; input state :$2. fips :$3. naics :$6. tflag :$1. TotEmp Q1Payroll AnPayroll Nestabs 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 Nestabs_1000_1499 Nestabs_1500_2499 Nestabs_2500_4999 Nestabs_5000 CenState :$2.; %end; 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 $&naicsfmt..; *--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 establishments: 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 ; length nestabs: 4 default=6; format totemp cbpemp.; run; proc sort data=temp&yr; by state county naics; run; *----In this final step we merge in metro-based geographic codes from the 2k census and most recent cbsa codes-; data &saslib..uscos&yr.(label="County totals for US, &yr" index=(state) compress=yes); merge xxgeos.uscntys(keep = state county Region Division MSACMSA PMSA NECMA ) georef.cbsacos(in=incbsas keep=state county cbsa cbsatype metrodiv year rename=(year=CBSAyr) where=(state ne '72')) temp&yr(in=incbp) ; by state county; if incbp; label cbsa='Core based (Metropolitan/Micropolitan) Statistical Area' metrodiv='Metropolitan Division (of CBSA)' cbsayr='CBSA as-of Year'; 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; %end; /******************************** COUNTY File Processing ENDS ************************************/ /******************************** MSA (CBSA)File Processing ************************************/ %if %index(&files,msa) or %index(&files,cbsa) %then %do; **********************************************; * convert MSA totals file *; **********************************************; libname georef '/pub/data/georef' access=readonly; %if &unzip=0 %then %do; filename cbpmsa "&datadir/cbp&yr.msa.txt" ; %end; %else %do; x cd &datadir; filename cbpmsa pipe "unzip -apq cbp&yr.msa.&compfiletype." ; %end; missing a b c e f g h i j k l m; data temp&yr; length cbsa $5; length naics $6 nlevel $1 Industry $6 SumLev $3; retain SumLev '310'; infile cbpmsa lrecl=550 %if &year gt 2000 %then %str(dsd firstobs=2 delimiter='2C0D'x);; %if %superq(dsd) eq %str() %then %do; input cbsa $5. @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.; %end; %else %do; input cbsa :$5. naics :$6. tflag :$1. TotEmp Q1Payroll AnPayroll Nestabs 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 Nestabs_1000_1499 Nestabs_1500_2499 Nestabs_2500_4999 Nestabs_5000 ; %end; retain Year "&year"; if _n_ gt &obsin then stop; * Limit the number of observations ; if naics='------' then industry=naics; else industry=compress(naics,'-/'); format industry $&naicsfmt..; *--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 cbsa='Metropolitan/Micropolitan Statistical Area (core based)'; label nestabs='# of establishments: total' Nestabs_1_4='# of establishments: 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 ; length nestabs: 4 default=6; format totemp cbpemp.; run; proc sort data=temp&yr; by cbsa naics; run; data &saslib..uscbsas&yr.(label="Metro/Micro-politan Stat Area data for US, &yr" compress=yes); merge georef.cbsapops(in=ingeoref drop=Popcen2k where=(cbsa ne ' ')) temp&yr(in=incbp); by cbsa; if not ingeoref or not incbp then do; if ingeoref and index(counties,'PR') then delete; if incbp then if first.cbsa; put "***cbsa not found on both cbp and georef sets: " cbsa= cbsaname= ingeoref= incbp= _n_=; _nbad+1; if _nbad ge 100 then do; put "******ABORTING DUE TO ERRORS (100+)******"; abort abend; end; if not incbp then delete; end; length Moflag $1; if index(counties,'MO') then Moflag='1'; else Moflag='0'; drop _: ; run; %end; /* **************** MSA file processing ends ****************************************************** */ %endmac: %mend cbpcnvt;