PROC FORMAT in SAS to Label Data Values
PROC FORMAT in SAS to Label Data Values PROC FORMAT in SAS allows you to create a mapping system that assigns descriptive labels to specific data values.
PROC FORMAT in SAS to Label Data Values
This can enhance data readability and interpretation in reports and analyses.
Below is an overview of how to effectively use PROC FORMAT with examples.
Basic Syntax
The syntax for PROC FORMAT is simple and straightforward:
proc format;
value points_range
25-high='High'
15-<25='Medium'
other ='Low';
run;
In this example, we create a mapping where:
- Values of 25 or greater are labeled as ‘High’.
- Values between 15 and 25 are labeled as ‘Medium’.
- All other values are labeled as ‘Low’.
Example Data
To demonstrate PROC FORMAT, let’s work with the following dataset:
/* Create dataset */
data my_data;
input team $ position $ points;
datalines;
A Guard 25
A Guard 20
A Guard 30
A Forward 25
A Forward 10
B Guard 10
B Guard 22
B Forward 30
B Forward 10
B Forward 10
B Forward 25
;
run;
/* View dataset */
proc print data=my_data;

Example 1: Formatting Values in a Frequency Table
Suppose we want to create a frequency table that displays the frequency of values in the points
column from the my_data
dataset.
Here’s how to do it initially, without formatting:
/* Calculate frequency of values in points column */
proc freq data=my_data;
table points;
run;
This command generates a table displaying the frequency of each unique value in the points
column. However, we wish to format these values to make them more interpretable as follows:
- High for values 25 or greater.
- Medium for values between 15 and 25.
- Low for any other values.
To achieve this, we can define the format and apply it to the frequency table:
/* Define formatting for points variable */
proc format;
value points_range
25-high='High'
15-<25='Medium'
other ='Low';
run;
/* Create frequency table using the defined format */
proc freq data=my_data;
table points;
format points points_range.;
run;
Now, the frequency table groups the points
values into the corresponding labels based on the formatting we defined.
Example 2: Creating a New Variable
In addition to formatting existing data, we can also use PROC FORMAT to create a new variable that translates numerical values into labeled categories. Here’s how to do that:
/* Define formatting for points variable */
proc format;
value points_range
25-high='High'
15-<25='Medium'
other ='Low';
run;
/* Create a new dataset with the points_range variable */
data new_data;
set my_data;
point_range = put(points, points_range.);
run;
/* View the new dataset */
proc print data=new_data;
In this example, we create a new variable called point_range
that assigns a value of Low, Medium, or High based on the corresponding points
variable values.
Conclusion
PROC FORMAT in SAS is a versatile tool for enhancing the clarity and interpretability of data. It allows you to assign meaningful labels to numerical values, facilitating better analysis and reporting.
Whether you’re summarizing data in frequency tables or creating new variables for better understanding, PROC FORMAT is an essential part of data manipulation in SAS.