x cd /pub/sas/formats/Tools; %let pgm=gen_zipname; filename pgm "&pgm..sas"; *--generate the $zipname format code based on georef.zipcodes with vintage Oct. 2009 ZIP code names. Previous format called $zipname that was for 3 states only is overwritten. jgb, June, 2010. And again, 11-25-13 to improve names for ZCTAs by tapping into the zcta_master set to override the georef.zipcodes (free federalgovernmentzipcodes data). --; %libname(georef) filename fmatfile '/pub/sas/formats/Szipname.sas'; libname sasctlgs clear; libname sasctlgs '/pub/sas/catalogs'; *<===This is where we keep our permanent SAS formats in the formats catalog----; proc sort data=georef.zcta_master(keep=zcta5 zipname psf where=(psf=1) rename=(zcta5=zip)) out=ournames; by zip; run; data zipnames; *et georef.zipcodes; length zip $5 zipname $64; merge georef.zipcodes (in=inzipcodes) ournames(in=inmaster); by zip; if zip ne ' '; *<--2 blanks made it onto the dataset--; if decommissioned='No'; if not inmaster then do; Source='FreeFed '; if ziptype='STANDARD' then zipname =location; else if ziptype='UNIQUE' then zipname=trim(scan(altnames,1,','))||', '|| location; else if ziptype='PO BOX ONLY' then zipname=trim(location)|| ' (PO Boxes)'; else zipname=location; end; else source='ZCTAmstr'; keep zip zipname; *** stab pop; run; /* ========================begin comment==================================== proc sort; by zip descending pop; run; data zipnamesv/view=zipnamesv; set zipnames; by zip; length arg $7; if not first.zip then arg=zip||stab; else arg=zip; run; ==========================end comment====================================== */ %genfmat(fmatname=zipname, savedoc=1, textfile=fmatfile, sasin=zipnames,argvars=zip,arglen=5, labelvar=zipname,labellen=64,runproc=0) run; proc format library=sasctlgs; %include fmatfile; run; options fmtsearch=(sasctlgs work); data _null_; set georef.zipcodes; *if mod(_n_,1000)=1; where zip=:'631'; put zip ziptype location= altnames= ' zipname=' zip $zipname.; run;