Reference: http://support.sas.com/resources/papers/proceedings12/048-2012.pdf
Save a Format:
Libname sasformat 'c:\sas\format';
Define Catalog:
Proc Format Library = sasformat.format1;
Copy formats in work library catalog to local permanent drive.
Proc catalog catalog=work.formats; copy out=sasformat.formats; run;
Check All the Formats in the Catalog:
Proc Catalog Catalog = sasformat.format1; contents; quit;
Check details of specific format (in the output window) in the Catalog:
Proc format fmtlib lib=sasformat.format1; select $gender; run;
Output details of specific format in the Catalog to a dataset:
Proc format cntlout=gender lib=sasformat.format1; select $gender; run;
Output multiple formats in the Catalog to a dataset:
Proc format cntlout=checkfmt lib=sasfmt.fmt; select $sexfmt $country $prorfmt $cuncfmt; run;
Setup Format Search Directory:
Options Fmtsearch = (sasformat.format1 work);
Turn Format Search Off:
Options Fmtsearch = ();
Hide Format Error Message and Format Error Note:
Options Fmtsearch = (sasformat.format1 work) NOFMTERR NONOTES;
Determine What Format Library is used for Format Search:
Proc Options option = FMTSEARCH;
Multiple Formats for Same Variable:
- format name in the same library should unique;
- format name is part of the definition of the varialbe that use the format.
- format name is the only connection of the variable to the catalog.
- by applying the same format name from different format libraries and catalogs in the fmtsearch option, you can have more than one format for each variable without changing the format name in the format statement in the data step. eg. english and french format for the same dataset.
Options Fmtsearch = (sasformat.englishfmt);
Options Fmtsearch = (sasformat.frenchfmt);
Delete Format Catalog:
Proc Dataasets Library=sasformat; Delete englishfmt (memtype=catalog); Delete frenchfmt (memtype = catalog); Quit;
Apply Formats of Variables in a Dataset:
In a data step:
Format Var1 Formatname1 Var2 Formatname2;
Delete Formats of Variables in a Dataset:
In a data step:
Format Var1 Var2; Format _all_;
Select and Exclude with Proc Format:
/* Select specific format, character format need to have $ prefix*/ /* adm is character format and ref is numeric format */ proc format library=formatlib cntlout=fmtname; select $adm ref; run; /* Exclude specific format */ proc format library=formatlib cntlout=fmtname; exclude $adm lastref; run;
Note that Select and Exclude can not be used together in one Proc Format procedure.