/******************************************************************** 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 postal abbreviations */ 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=1, /* 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); %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; %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 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; %if &slctedit ne %then %do; %&slctedit %end; output; 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--; %*-- states processing --; %if %index(&files,state) %then %do; data &saslib..states&yr.(label="u.s. states data for &yr" compress=yes); length state stab $2 AreaName $40; ****read the data****; stab=put(state,$fipstab.); retain SumLev '040'; AreaName=put(state,$state.); run; %end; %*-----------states file processing---------------; %*------------counties file processing-------------------; %if %index(&files,counties) %then %do; %local nst st; %let nst=1; %let st=%scan(&states,&nst); data &saslib..uscos&yr.(label="County totals for US, &yr" compress=yes); length state stab $2; length fipco $5; length county $5; format county $fipcnty.; length msa $4; *--no format used but $metro. would work--; length mtype $1; label mtype='metro type'; length pmsa $4; *--left blank unless mtype='c'--; run; %end; %*--counties processing; %endmac: %mend cbpcnvtn;