x cd /pub/sas/formats/Tools; %let pgm=gen_statefmts; filename pgm "&pgm..sas"; *---For each state and PR generate 2 format codes such as nycnty and nyplace that will take as an argument the county/place fips codes with or without the qualifying state. So the args '36001' and '001' will yeild the same result in the $nycnty format code. Useful for getting names on these variables from dexter when accessing a single states data. jgb, OSEDA, 4-2011. ---*; %libname (pl942010); libname pl94 (pl942010); libname sasctlgs clear; libname sasctlgs '/pub/sas/catalogs'; options fmtsearch=(sasctlgs work); %macro doit(state,stab); data counties places; set pl94.&stab.sums(where=(sumlev in ('050','160')) keep=state county placefp sumlev areaname) end=last; length arg $7 ; if sumlev='160' then do; arg=state||placefp; output places; arg=placefp; output places; end; else if sumlev='050' then do; arg=county; output counties; arg=substr(county,3,3); output counties; end; if last then do; areaname='Outside any place'; arg=state||'99999'; output places; arg='99999'; output places; arg=state; areaname=put(state,$state.); output counties; end; filename text "/pub/sas/formats/statefmts/S&stab.cnty.sas"; options nomprint; %genfmat(setin=counties, argvars=arg,labelvar=areaname, arglen=7,labellen=40, fmatname=&stab.cnty) run; filename text "/pub/sas/formats/statefmts/S&stab.place.sas"; %genfmat(setin=places, argvars=arg,labelvar=areaname, arglen=7,labellen=40, fmatname=&stab.place) run; options mprint; data _null_; set places(in=inp obs=6) counties(in=inc obs=6); if inp then put arg= arg $&stab.place.; else put arg= $&stab.cnty.; run cancel; %mend doit; %**doit(10,de); %dostates(n=52);