x cd /pub/sas/formats/Tools; %let pgm=wcfmats; filename pgm "&pgm..sas"; *----Utility module used to create alternate format codes in which we pre-append the code to the label for an existing format code. Generates a new format code named <1st 6 chars of old format, if name that long>||wc . So, for example, $sumlev is used to generate $sumlevwc. . ---; libname sasctlgs clear; libname sasctlgs '/pub/sas/catalogs'; *----We copied this macro to the macro library so should be able to omit this source in the future======================; %macro cnvt2wc(fname,library=sasctlgs,fnameout=,source=0,lenarg=,arglen=,sourcelib=%str(/pub/sas/formats)); %local lfn memname; %if &arglen ne %str() %then %let lenarg=&arglen; %*<---an alias--; %if %substr(&fname,1,1)=%str($) %then %do; %let fname=%substr(&fname,2); %let type=c; %end; %else %let type=n; %let lfn=%length(&fname); %if %superq(fnameout) = %str() %then %do; %if &lfn <= 6 %then %let fnameout=&fname.wc; %else %let fnameout=%substr(&fname,1,6)wc; %end; %if type=c %then %let memname=S&fname; %else %let memname=&fname; proc format cntlout=_cntlout %if &source %then %do; ; *<---end proc format stmt without a library= spec---; %include "&sourcelib(&memname..sas"; %end; %else %do; library=&library; select %if &type=c %then %str($);&fname ; %end; run; data _cntlin; set _cntlout; fmtname="&fnameout"; length=length + &lenarg +1 ; label=trim(start)||' '||label; max=length; run; proc print data=_cntlin(obs=50); title3 "_cntlin"; run; proc format library=&library cntlin=_cntlin; run; %mend cnvt2wc; options mprint; %cnvt2wc($sumlev,lenarg=3) %cnvt2wc($county,lenarg=5) %cnvt2wc($cbsa,lenarg=5) %cnvt2wc($state,lenarg=2) run; data _null_; code='150'; put code= $sumlevwc.; run;