SAS: PROC Format using dataset to create multiple formats

The following codes create two department formats: one formats ‘key’ variable to ‘deptid’ variable; the other formats ‘deptid’ variable to ‘deptname’ variable. Output the format in the work library. The convenience of the data step approach is to include all the related formats in one data set, eg. fm_dept. When the formats are required, simply using proc format and cntlin=dataset option to activate the formats.

data fm_depts;
set map_to_depts (keep = key deptid deptname);
length fmtname $ 8 type $ 1 label $70 start $ 10;
fmtname='$mapdepc';
start=key;
label=deptid;
type='c';
output;
fmtname='$mapdepn';
start=deptid;
label=deptname;
type='c';
output;
keep start fmtname label type;
run;
proc sort nodupkey; by fmtname start; run;
proc format library = work cntlin= fm_depts; run;

Format can also be created manually in the catalog as follows. A format catalog can contain many formats.

libname sasfmt  'X:\Work\SAS\data source\format';
proc format library =sasfmt.commonfmt;
run;
options fmtsearch = (sasfmt.commonfmt);
proc format library=sasfmt.commonfmt ;
value
$year
'2015' = '15'
'2016' = '16'
'2017' = '17'
'2018' = '18;
value
$ftpt
'FT' = '1'
'PT' = '2'
;
run;