x cd /mscdc/sas/formats/Tools; %let pgm=cnam2fp; filename pgm "&pgm..sas"; *--generate the $cnam2fp format code: arg is state postal abbrev + space + county name (all upper case), and result is 5-digit FIPS code or a blank if not found. Uses gics90 as data source--; %libname(gics90); %libname (popests); filename text '/mscdc/sas/formats/Scnam2fp.sas'; title 'Generate $cnam2fp SAS format code'; /* *<==================comment out ============================== ==========================end comment=============================== */ data cnames; set gics90.counties(keep=state county areaname); ic=index(areaname,'County'); if ic then substr(areaname,ic)=' '; areaname=compress(areaname,"'."); *<--remove periods and apostrophes-; areaname=upcase( put(state,$fipstab.)||" "||areaname); *-e.g. "AL AUTAUGA"-; run; *--proc format only takes 16 char args (until V7)--; %genfmat(sasin=cnames, fmatname=cnam2fp, argvars=areaname, arglen=16, labelvar=county, labellen=5, other=' ', runproc=1) run; data _null_; infile text obs=20; input; file print; put _infile_; title2 'First 20 Lines of Scounty.sas file'; run; *--test use--*; data recodes; set popests.uscom97(keep=state county areaname slvl); length arg $16 fipco $5; where slvl='050'; ic=index(areaname,'County'); if ic then substr(areaname,ic)=' '; areaname=compress(areaname,"'."); *<--remove periods and apostrophes-; arg=upcase( put(state,$fipstab.)||" "||areaname); *-e.g. "AL AUTAUGA"-; recode=put(arg,$cnam2fp.); if county ne recode then put _all_; run;