/******************************************************************** This macro will read one or more county business pattern files in CSV (comma-delimited) files format such as was used for the 20XX files stored on the Bureau web site, (http://www.census.gov/econ/cbp/download/index.htm ) starting with the 2007 data year. (See companion macro cbpcnvt.sas for code used to convert earlier years of data with comparable resulting datasets). Note that we do NOT keep the newly added noise flag values on these data sets. Users who need to see those values can use the Bureau interactive report generator at http://www.census.gov/econ/cbp/index.html . This macro being invoked by pgm cnvtcbpYY.sas starting with the 2012 data, June 2014. Note that we have a separate and similar zbpcnv2 sas macro that is invoked to process the ZIP code level data. ********************************************************************/ /* Update history: 11-08/11: Begin new version, using cbpcnvt.sas as template. 06-17-14: Minor tweaks. Eliminate refs to ZIP (codes) data file. 04-25-15: Changing how we ID Puerto Rico counties on georef.cbsapops because no State variable. 04-27-15: Adding code to read xtab2 field starting with 2013 data. In dobysize macro. */ /********************************************************************/ /* BEGIN MACRO DEFINITION */ /********************************************************************/ %MACRO cbpcnv2( revdate=%str(04/25/2016), /* *<=========Date of last revision======== */ yr=, /* REQUIRED. specifies 2-digit year of data */ files=all, /* same as "us states counties msas", so we read and convert all 4 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/downloads), /* path of input files. The directory where we store .zip files downloaded from the Bureau web site -- http://www.census.gov/econ/cbp/download/, for example OR ftp2.census.gov/econ20XX */ unzip=1, /* Flag. =1 means 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. unzip=0 means we unzipped it already and we read a .txt (should be .csv) file. */ unzipopts=, /* options for the unzip command to read downloaded .zip files */ termstr=crlf, /* termstr parm specified on the infile statement. Default says it is windows format. */ saslib=cbp, /* libref of output datasets. SAS output dataset names are: ustots&yr, states&yr, uscntys&yr, uscbsas&yr and usziptots&yr/uszipsdetail&yr. The invoking program obviously should contain a libname statement to define this libref.*/ obsin=9999999, /* # of input records to be processed. For test runs. */ cbsacos=cbsacos, /* we look for CBSA reference data in georef.&cbsacoset . Default points to latest available data */ cbsapops=cbsapops, /* we look for CBSA latest pop estimates data in georef.&cbsapops . Default points to latest available data */ obs=, /* alias for obsin */ debug=0); /* debug=1 triggers some extra output msgs */ %Put %STR( ); %PUT ***************************************************************; %put * cbpcnv2 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); %if &files=all %then %let files=us states counties msas; %let states=%lowcase(&states); %if &termstr=%str() %then %let termstropt=%str(); %else %let termstropt=%str(termstr=&termstr); %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 yr must be specified as 2-digit year of data******; %put *** value specified (&yr) is not 2 digits. ; %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 or %eval(&yr) lt 07 %then %do; %put ; %put ********parm yr=&yr must be (and is not) a 2-digit year between 07 and 20******; %put %str( ) macro will abort and no processing will be done*****; %goto endmac; %end; %local year; %let year=20&yr; %local dsd; %*--assign value of null or dsd depending on wether we want to declare input as a CSV file; %let naicsfmt=naics02_; %*--naics02_ starting with 03 data; %if &unzipopts= %then %do; %*--starting with 2014 we drop the ascii ("a") spec---; %if &yr ge 14 %then %let unzipopts=pq; %else %let zbpopts=pqa; %end; %let compfiletype=zip; %if &debug=2 %then %put _all_; *%---This utility submacro used to generate code for all the different employment size categories. We use it to both read the relevant fields and then to process the data after it is read. We invoke it twice in a processing step, once during the input stmt and then again after all data are read and we process to assign missing values based upon the flags read (and to handle the NoiseFlags strings). ----; %macro dobysize(function); %local size sizes i j flag flagvals sizes; %let flagvals=ABCEFGHIJKLM; %let sizes=%str(1_4 5_9 10_19 20_49 50_99 100_249 250_499 500_999 1000); %let function=%lowcase(&function); %do i=0 %to 9; %if &i=0 %then %let size=%str(); %else %let size=%scan(&sizes,&i); %if &function=read %then %do; %if &i=0 and (&year ge 2013) and (&year le 2014) %then %str( xtab2 :$1. ); %if &i=0 %then %str(EmpFlag :$1. Emp_NF :$1. TotEmp QP1_NF :$1. Q1Payroll AP_NF :$1. AnPayroll Nestabs ); %else %str(F&size :$1. E&size.NF :$1. Emp&size Q&size.NF :$1. Wages1Q_&size A&size.NF :$1. WagesAn_&size Nestabs_&size); %end; %else %if &function=process %then %do; %if &i ne 0 %then %do; substr(EmpNoiseFlags,&i,1)=E&size.NF; drop E&size.NF; substr(W1QNoiseFlags,&i,1)=Q&size.NF; drop Q&size.NF; substr(AnPNoiseFlags,&i,1)=A&size.NF; drop A&size.NF; substr(DataSupFlags,&i,1)=F&size; drop F&size; if F&size ne ' ' then do; %do j=1 %to 12; %let flag=%substr(&flagvals,&j,1); %*--if the flag has a value of M (for example) then we assign the Emp&size variable a (missing) value .M --; if F&size="&flag" then Emp&size=.&flag ; %if &j ne 12 %then %str ( else ); %end; end; if Q&size.NF='D' then Wages1Q_&size=.D; else if Q&size.NF='S' then Wages1Q_&size=.S; if A&size.NF='D' then WagesAn_&size=.D; else if A&size.NF='S' then WagesAn_&size=.S; %end; %else %do; if EmpFlag ne ' ' then do; %do j=1 %to 12; %let flag=%substr(ABCEFGHIJKLM,&j,1); %*--if the flag has a value of M (for example) then we assing the Emp&size variable a (missing) value .M --; if EmpFlag="&flag" then TotEmp=.&flag ; %if &j ne 12 %then %str ( else ); %end; end; %end; %end; %*---function=process do group---; %end; %*--do i=1 to 9 loop--; %mend dobysize; /******************************** US File Processing ************************************/ %if %index(&files,us) %then %do; ********************************************; * convert u.s. totals file *; ********************************************; %if &unzip=0 %then %do; ***NOTE: Assumes file was converted to Unix/Windows using unzip -a option. On Linux, it bombs without this-; filename cbpus "&datadir/cbp&yr.us.txt" ; %end; %else %do; x cd &datadir; filename cbpus pipe "unzip -&unzipopts cbp&yr.us.&compfiletype." ; %end; missing a b c e f g h i j k l m d s; data &saslib..ustots&yr.(label="U.S. totals for &year"); length naics $6 nlevel $1 Industry $6 SumLev $3; retain Year "&year"; retain SumLev '010'; *<---Geographic Summary Level code, as used on CB Summary files--; infile cbpus lrecl=1024 dsd firstobs=2 &termstropt; ** length _nflag $1; length EmpNoiseFlags W1QNoiseFlags AnPNoiseFlags DataSupFlags $9; label EmpNoiseFlags='1st Qtr Employment Noise Flags by Size' W1QNoiseFlags='1st Qtr Wages Noise Flags by Size' AnPNoiseFlags='Annual Payroll Noise Flags by Size' DataSupFlags='Data Suppression Flags by Size'; label EmpFlag='TotEmp Suppression Flag' AP_NF='AnPayroll Noise Flag' QP1_NF='Q1Payroll Noise Flag'; format EmpNoiseFlags AnPNoiseFlags DataSupFlags $char9.; input _usind :$2. naics :$6. %if &year ge 2008 %then %str( LFO :$1. ); %*----we also added code to the dobysize macro to read and skip the xtab2 field starting in 2013---; %dobysize(read) ; if _n_=1 then do; put "***We list first record read from input file***"; list; end; 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; if naics='------' then industry=naics; else industry=compress(naics,'-/'); if naics='------' then nlevel=0; else do; nlevel= length( industry)-1; end; format industry $&naicsfmt.. ; *--so internally they are similar, but industry prints as the name-; if Emp_NF='D' then TotEmp=.D; else if Emp_NF='S' then TotEmp=.S; if QP1_NF='D' then Q1Payroll =.D; else if QP1_NF='S' then Q1Payroll=.S; if AP_NF='D' then AnPayroll=.D; else if AP_NF='S' then AnPayroll=.S; %dobysize(process) ; 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'; %if &year ge 2008 %then %do; label LFO='Legal Form of Orgnztn'; %end; 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.; drop _:; 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 -&unzipopts cbp&yr.st.&compfiletype." ; %end; missing a b c e f g h i j k l m d s; data states&yr; length state stab $2 AreaName $20 LFO $1; length naics $6 nlevel $1 Industry $6 SumLev $3; retain SumLev '040'; retain Year "&year"; label lfo='Legal Form of Orgnztn'; length EmpNoiseFlags W1QNoiseFlags AnPNoiseFlags DataSupFlags $9; label EmpNoiseFlags='1st Qtr Employment Noise Flags by Size' W1QNoiseFlags='1st Qtr Wages Noise Flags by Size' AnPNoiseFlags='Annual Payroll Noise Flags by Size' DataSupFlags='Data Suppression Flags by Size'; label EmpFlag='TotEmp Suppression Flag' Emp_NF='TotEmp Noise Flag' AP_NF='AnPayroll Noise Flag' QP1_NF='Q1Payroll Noise Flag'; format EmpNoiseFlags AnPNoiseFlags DataSupFlags $char9.; infile cbpst lrecl=1024 dsd &termstropt firstobs=2 ; input state :$2. naics :$6. lfo :$1. %dobysize(read) CenState :$2.; stab=put(state,$fipstab.); AreaName=put(state,$state.); 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 Emp_NF='D' then TotEmp=.D; else if Emp_NF='S' then TotEmp=.S; if QP1_NF='D' then Q1Payroll =.D; else if QP1_NF='S' then Q1Payroll =.S; if AP_NF='D' then AnPayroll=.D; else if AP_NF='S' then AnPayroll=.S; %dobysize(process) _toterror + _error_; if _toterror ge 20 then do; put '***20 or more errors - program aborting.... ' ; abort abend; 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 _: ; length nestabs: 4; format totemp cbpemp.; drop CenState; *--added 6/2014. Was not being read correctly anyway--; run; proc sort data=states&yr out= &saslib..states&yr.(label="U.S. States data for &year" index=(state) ); by state; *---it has been known to come sorted by census state (censtat)---; run; %end; /******************************** STATE File Processing ENDS ************************************/ /******************************** COUNTY File Processing ************************************/ %if %index(&files,counties) %then %do; ***************************************; * convert County 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 -&unzipopts cbp&yr.co.&compfiletype." ; %end; missing a b c e f g h i j k l m d s ; data temp&yr; length County $5; format county $county.; length state stab $2; length fipco $5; length LFO $1 naics $6 nlevel $1 Industry $6 SumLev $3; retain SumLev '050'; retain Year "&year"; ***label lfo='Legal Form of Orgnztn'; label EmpFlag='TotEmp Suppression Flag' Emp_NF='TotEmp Noise Flag' AP_NF='AnPayroll Noise Flag' QP1_NF='Q1Payroll Noise Flag'; infile cbpco lrecl=1024 dsd firstobs=2 &termstropt; ****Header record on counties file (part): "fipstate","fipscty","naics","empflag","emp_nf","emp","qp1_nf","qp1","ap_nf","ap","est","n1_4" ---; input state :$2. fips :$3. naics :$6. EmpFlag :$1. Emp_NF :$1. TotEmp QP1_NF :$1. Q1Payroll AP_NF :$1. AnPayroll Nestabs %addsfxs(nestabs_,1_4 5_9 10_19 20_49 50_99 100_249 250_499 500_999 1000) Nestabs_1000_1499 Nestabs_1500_2499 Nestabs_2500_4999 Nestabs_5000 ; *** CenState :$2.; *<--commented out 6/2014--; if _n_=1 then do; put '***List first record on cbpco file*** '; list; end; stab=put(state,$fipstab.); fipco=trim(state)||trim(fips); County = fipco; if _n_ gt &obsin then stop; 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 EmpFlag ne ' ' then do; %do jj=1 %to 12; %let flag=%substr(ABCEFGHIJKLM,&jj,1); %*--if the flag has a value of M (for example) then we assing the Emp&size variable a (missing) value .M --; if EmpFlag="&flag" then TotEmp=.&flag ; %if &jj ne 12 %then %str ( else ); %end; end; else if Emp_NF='D' then TotEmp=.D; else if Emp_NF='S' then Emp_NF=.S; *--Adding the "else" here means EmpFlag trumps Emp_NF--; if QP1_NF='D' then Q1Payroll =.D; else if QP1_NF='S' then Q1Payroll =.S; if AP_NF='D' then AnPayroll=.D; else if AP_NF='S' then AnPayroll=.S; 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)'; length nestabs: 4 default=6; format totemp cbpemp.; run; %if &obsin ne 9999999 %then %do; %put ***Postprocessing of counties file skipped due to obsin indicating a test run*** ; %goto endcounties; %end; 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-; %global cbsayr; data &saslib..uscos&yr.(label="County totals for US, &yr" index=(state) compress=yes); merge xxgeos.uscntys(keep = state county Region Division ) georef.&cbsacos&cbsayr(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; %endcounties: %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 -&unzipopts cbp&yr.msa.&compfiletype." ; %end; missing a b c e f g h i j k l m d s; data msatemp&yr; length cbsa $5; length naics $6 nlevel $1 Industry $6 SumLev $3; retain SumLev '310'; retain Year "&year"; infile cbpmsa lrecl=1024 dsd &termstropt firstobs=2 ; input cbsa $ naics EmpFlag :$1. Emp_NF :$1. TotEmp QP1_NF :$1. Q1Payroll AP_NF :$1. AnPayroll Nestabs %addsfxs(nestabs_,1_4 5_9 10_19 20_49 50_99 100_249 250_499 500_999 1000) Nestabs_1000_1499 Nestabs_1500_2499 Nestabs_2500_4999 Nestabs_5000; 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 EmpFlag ne ' ' then do; %do jj=1 %to 12; %let flag=%substr(ABCEFGHIJKLM,&jj,1); %*--if the flag has a value of M (for example) then we assing the Emp&size variable a (missing) value .M --; if EmpFlag="&flag" then TotEmp=.&flag ; %if &jj ne 12 %then %str ( else ); %end; end; else if Emp_NF='D' then TotEmp=.D; else if Emp_NF='S' then Emp_NF=.S; *--Adding the "else" here means EmpFlag trumps Emp_NF--; if QP1_NF='D' then Q1Payroll =.D; else if QP1_NF='S' then Q1Payroll =.S; if AP_NF='D' then AnPayroll=.D; else if AP_NF='S' then AnPayroll=.S; 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)'; length nestabs: 4 default=6; format totemp cbpemp.; run; proc sort data=msatemp&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=Popcen: where=(cbsa ne ' ' and (index(counties,'PR')=0) )) msatemp&yr(in=incbp) end=_last; by cbsa; if not incbp then do; if index(counties,'PR')=0 then _noCBPdata+1; put @7 "***cbsa not found in CBP data: " cbsa= cbsaname= counties= _n_=; goto cklast; end; if not ingeoref then do; if first.cbsa then do; put "***cbsa not found on georef.cbsapops dataset: " cbsa= +1 "cbsaname=" cbsa $cbsa. counties= _n_=; _nogeoref +1; if _nogeoref ge 100 then do; put "******ABORTING DUE TO ERRORS (100+)******"; abort abend; end; end; end; length Moflag $1; if index(counties,'MO') then Moflag='1'; else Moflag='0'; output; drop _: ; cklast: if _last then put / "***uscbsas&yr merge step completed with: " _noCBPdata= _nogeoref= ; run; %end; /* **************** MSA file processing ends ****************************************************** */ %endmac: %mend cbpcnv2;