Written and maintained by CASRAI Editorial Board
Published
On this page
PROC FORMAT in SAS creates reusable rules that display stored values as labels, grouped categories or custom representations. Define the rules with PROC FORMAT, then attach them with a FORMAT statement. Keeping the stored codes, displayed labels and format definitions distinct makes research tables easier to check and reproduce.
What PROC FORMAT is used for in research
A dataset might store a survey response as 1, 2 or 3 while a report needs meaningful category names. A user-defined format supplies that presentation rule. The format definition belongs to a catalog; the dataset can hold an association between a variable and the format’s name. The association and the definition are separate things.
The SAS procedures guide distinguishes creating a format from applying one. PROC FORMAT creates it. A FORMAT statement associates an existing format with variables. Formatting a numeric code does not turn the stored variable into text. If the required output is a new character column containing the label, SAS’s Using Formats reference documents the PUT function for that operation.
This distinction matters when reviewing an analysis: a labelled listing can look correct even though the underlying codes need inspection. The example below prints a raw-code copy beside the formatted variable, then shows how to retain the definitions separately. For the surrounding program structure, the SAS DATA-step and PROC-step guide explains where data creation ends and procedure execution begins.
Formats can also affect classification. SAS documents that PROC FREQ groups observations by their formatted values. Combining several codes under one label therefore combines frequency-table levels. Treat a grouping format as part of the analysis specification, rather than assuming it changes only a report’s appearance.
How to install or access PROC FORMAT
PROC FORMAT is documented in Base SAS; it is a procedure to run within a SAS programming session. Use your institution’s SAS environment and code editor to submit the examples. No separate format-definition package is needed. These examples use SAS language statements rather than a sequence of interface menus.
For practice, SAS describes SAS OnDemand for Academics as a cloud learning environment with browser access to SAS Studio. Its stated audience includes educators, students and independent learners, and local software management is unnecessary for that route. Follow SAS’s own access link and learning terms. The fictional records below are suitable for practising the mechanics; access to a learning environment is a separate decision from authorization to upload research records.
How to create and apply SAS formats step by step
Start with a small mapping, apply it to a clearly identified variable, and inspect both the codes and labels. The following illustrative composite uses invented records and project-site names. It demonstrates syntax and expected mappings; it is not a study dataset or an empirical result.
- Check the variable type and code definitions. A numeric format applies to a numeric variable; a character format uses a name beginning with a dollar sign. If the source was imported, use the PROC CONTENTS variable-attribute listing to check its type. Resolve an ingestion problem with the PROC IMPORT data-type checks before designing labels around an accidental type.
- Create the definitions. VALUE defines the numeric mapping named statusfmt. VALUE $sitefmt defines the character mapping. Put the codes or ranges on the left of each equals sign and quoted display labels on the right. End each definition with a semicolon, and end the procedure with RUN.
- Associate the formats. In the DATA step, FORMAT connects status to statusfmt. and site to $sitefmt. The period belongs on a format reference, while the VALUE definition uses the name without that period. The raw_status assignment creates a separate numeric copy for inspection.
- Print a small result and review the log. Inspect the two status columns together. Keep an explicit label for an unexpected code during validation so an unanticipated value does not silently receive a plausible substantive category.
proc format;
value statusfmt
1 = 'Complete'
2 = 'In progress'
3 = 'Not started'
. = 'Missing'
other = 'Unexpected code';
value $sitefmt
'A' = 'North site'
'B' = 'South site'
other = 'Unmapped site';
run;
data work.format_demo;
input record_id status site $;
raw_status = status;
format status statusfmt. site $sitefmt.;
datalines;
1 1 A
2 2 B
3 3 A
4 . X
5 2 B
;
run;
proc print data=work.format_demo noobs;
var record_id raw_status status site;
run;
The expected status displays, in record order, are Complete, In progress, Not started, Missing and In progress. The corresponding raw codes remain 1, 2, 3, missing and 2. Sites A and B display as North site and South site; X takes the explicit Unmapped site branch. These expectations follow directly from the invented mapping, giving a reviewer a compact check against the program’s output.
Create a character label column when needed
Use PUT when another step needs the label as data rather than a format association. This additional DATA step retains the example dataset and writes the character result to a new variable:
data work.format_labels;
set work.format_demo;
length status_label $20;
status_label = put(status, statusfmt.);
run;
The declared length accommodates the example’s longest label. Here status remains numeric and status_label is character. Decide which representation a downstream file needs before exporting: a format association and a separately stored string serve different purposes. Retaining both during validation makes the intended transformation visible.
Use ranges and grouped codes deliberately
VALUE can associate multiple discrete codes with one label, such as 2,3 = 'Incomplete'. Numeric ranges use a hyphen, such as 1-3 = 'First three codes'. A range includes intervening numeric values, so it is different from enumerating only 1, 2 and 3. Select the form that expresses the codebook, rather than choosing the shorter spelling.
The procedure also supports LOW, HIGH and an exclusion marker at a range boundary. For a continuous measurement split, inspect the boundary itself and nearby values; do not translate an integer-only example into continuous intervals without reviewing the endpoints. OTHER supplies a fallback for otherwise unmatched values. In this example the fallback is a validation label, not a claim that all unknown codes mean the same research outcome.
Retain definitions for another session
By default, PROC FORMAT writes to WORK.FORMATS, which is temporary. SAS documents permanent catalogs selected with LIBRARY= and catalog lookup controlled with FMTSEARCH. Saving a dataset with a format association does not by itself preserve the catalog entry it names.
For a reproducible handoff, retain the definition program with the analysis or use a permanent catalog that later sessions can locate. The SAS formats reference documents both approaches. Record the catalog location alongside the analysis instructions; the next analyst needs the actual definitions as well as the variable names. A control dataset provides another inspectable representation, described below.
How to read the output
Distinguish a formatted data listing from a report about the format definition. PROC PRINT above shows observations with their display rules applied. PROC FORMAT with FMTLIB shows the rules themselves. An ordinary definition step need not produce a displayed table merely because it ran successfully.
proc format library=work fmtlib;
select statusfmt $sitefmt;
run;
proc format library=work cntlout=work.format_control;
select statusfmt $sitefmt;
run;
The FMTLIB report identifies the format and lists START, END and LABEL entries. NUMBER OF VALUES counts defined values or ranges; it is not the number of research observations. Length fields describe formatting widths. Compare the rules with the intended codebook rather than interpreting this report as a frequency distribution.
SAS notes that the compact FMTLIB display can truncate long labels. CNTLOUT creates a control dataset for inspecting the definitions as data. It includes the format name, range endpoints, label and type information. Preserve those fields together: the label alone does not identify the input values it describes.
The documented reverse operation is CNTLIN. For example, proc format library=work cntlin=work.format_control; run; rebuilds definitions from the control dataset. If constructing such a dataset yourself, FMTNAME, START and LABEL are required for numeric and character formats; additional fields describe type and ranges. Review the generated control dataset before attempting to maintain one by hand.
The data table below compares the artifacts produced by these operations with a derived label column. It is a workflow reference compiled from the SAS procedure and formats documentation, helping distinguish a definition, its association and its materialized output.
Troubleshooting PROC FORMAT
A format cannot be found in a later session
Check where the definition was stored and whether the new session can find that catalog. A definition created only in WORK belongs to the earlier session. Recreate it from retained source, or make the permanent library available and check FMTSEARCH. Diagnose availability before changing the variable’s labels.
SAS’s FMTERR setting stops a DATA or PROC step when a required user-defined format is unavailable. NOFMTERR allows processing with a default format, but SAS explicitly warns that the user-defined information is lost. Continuing with defaults therefore does not establish that the intended categories were used.
Categories collapse or missing records disappear
Inspect the mapping before interpreting a frequency table. The SAS Grouping with Formats documentation explains that PROC FREQ uses formatted levels. Different codes sharing a label can become one category, even though the dataset still contains their distinct stored values.
The same reference shows a subtler case: a format combines an ordinary code and numeric missing under one label, and PROC FREQ treats the entire group as missing. MISSING or MISSPRINT is needed to display that level. Specify missing-value handling deliberately instead of assuming that a visible word such as Missing makes the group an ordinary nonmissing category.
A definition or its displayed label is unexpected
Check the name, variable type and punctuation against the definition. User-defined format names cannot end in a number. Character format names begin with a dollar sign. Review overlapping ranges and explicit missing branches before expanding OTHER to conceal unexplained values.
Finally, separate display-width problems from mapping problems. Compare the FMTLIB description with CNTLOUT when a long label seems incomplete. If a separate label column was created with PUT, also inspect that receiving variable’s declared length. A correct mapping and a sufficiently long storage field are separate checks.
Free alternatives to PROC FORMAT
R offers free-software tools for related category-labelling tasks. Its project documentation identifies R as Free Software under the GNU GPL. The following functions provide two different approaches; neither is a SAS format-catalog loader.
| R tool | Related task | Difference to check |
|---|---|---|
| factor() | Assign labels to specified category levels. | Creates a factor with integer codes and a levels attribute. Unmatched inputs become NA. |
| cut() | Divide numeric observations into labelled intervals. | Breakpoints and interval closure define membership; observations outside the breaks become NA. |
For a new labelled category alongside a numeric source, an illustrative R expression is factor(status, levels = c(1, 2, 3), labels = c('Complete', 'In progress', 'Not started')). Keep the source vector when its original codes matter. The factor reference warns that applying as.numeric to a factor returns its encoding rather than reliably recovering those source values.
For intervals, R’s cut reference documents right-closed intervals as the default and provides include.lowest to control the outer boundary. Match the intended category definition explicitly when translating a SAS grouping rule. Similar-looking labels are insufficient evidence that two programs assign every boundary or missing value to the same category.
Sources
- SAS: Base SAS 9.4 Procedures Guide, Seventh Edition, FORMAT Procedure, checked 2026-11-17.
- SAS 9.4 Formats and Informats: Using Formats, checked 2026-11-17.
- SAS 9.4 Procedures Guide: Grouping with Formats, checked 2026-11-17.
- SAS: Results: FORMAT Procedure, checked 2026-11-17.
- SAS: OnDemand for Academics, checked 2026-11-17.
- R documentation: Factors, checked 2026-11-17.
- R documentation: Convert Numeric to Factor, checked 2026-11-17.
- R Project: What is R?, checked 2026-11-17.
Data: SAS format workflow: definitions, associations and output artifacts
Original cross-reference compiled from the SAS procedures and formats documentation. It distinguishes the artifact produced by six format operations and the documented information each artifact contains, rather than treating all formatted output as stored text.
| Operation | Artifact | Information represented | Documented distinction | Source |
|---|---|---|---|---|
| PROC FORMAT without LIBRARY= | WORK.FORMATS catalog | User-defined formats or informats | Temporary definitions for the current SAS session | Base SAS 9.4 Procedures Guide, FORMAT concepts |
| FORMAT in a DATA step | Dataset descriptor information | Association of a variable with a format | The format definition must also be available when used | SAS 9.4 Using Formats |
| PUT function assigned to a new variable | Character variable | Formatted value returned by the function | A character result rather than a format association | SAS 9.4 Using Formats |
| FMTLIB | Displayed format-description table | Format name, range endpoints, labels and widths | Compact display can truncate labels | Base SAS 9.4 Procedures Guide, FORMAT output |
| CNTLOUT= | Output control SAS dataset | Format names, ranges, labels and definition attributes | Can supply input to a later CNTLIN= operation | SAS Results: FORMAT Procedure |
| CNTLIN= | Format or informat catalog entries | Definitions constructed from an input control dataset | FMTNAME, START and LABEL required for numeric and character formats | SAS Results: FORMAT Procedure |
Sources
- SAS: Base SAS 9.4 Procedures Guide, Seventh Edition (accessed 2026-11-17)
- SAS 9.4 Formats and Informats: Using Formats (accessed 2026-11-17)
- SAS: Results: FORMAT Procedure (accessed 2026-11-17)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







