x cd /pub/data/cbp/Tools; %let pgm=naics_codes2002; filename pgm "&pgm..sas"; *---Read the NAICS (North American Industrial Classification System) industry codes file as provided with the latest (2005) CBP data. Create cbp.naics2002 dataset and $naics02 format code (source and catalog entry). J. Blodgett, June, 2007 See naics_codes setup for the OLD CODES sas used prior to 2002. ---*; filename naicsin '../naics2002.txt'; libname cbp '/pub/data/cbp'; filename format '/pub/sas/formats/Snaics02.sas'; data cbp.naics2002(label='Each obs represents 1 NAICS industry code as of 2002'); infile naicsin truncover firstobs=2; length naics2 $2. naics altnaics $6;; retain naics2; input naics $6. naics_name $80. ; altnaics=compress(naics,'-/'); label naics2='Major Industry Group'; length level 3; if naics='------' then level=0; else level= length( altnaics)-1; if level=1 then naics2=naics; *<---2-digit NAICS code, same as major industry code--; label naics2='Major Industry'; run; data cbp.naics2(label='Each obs represents 1 2-digit NAICS level'); set cbp.naics; where level=1; drop naics level; run cancel; *---we already have this data set from earlier processing. Nothing changed at this level.--; proc print data=cbp.naics2002(obs=50); title2 '1st 50 Obs on cpb.naics2002'; run; data genfmats; set cbp.naics2002; output; if naics ne altnaics and altnaics ne ' ' then do; naics=altnaics; output; end; drop altnaics; run; options NOmprint; *--we changed the name from naics02_ to naic02_ to avoid proc export glitch--; %genfmat(setin=genfmats, argvars=naics,arglen=6, labelvar=naics_name, labellen=80, fmatname=naic02_, textfile=format, savedoc=0) run; *--test the format codes to insure they work---; data _null_; set cbp.naics2002; where naics=:'236' or naics=:'237'; put naics2 naics2 $naics2_. naics naics $naics02_.; run;