Format Data Sets
Sometimes we prefer to represent the analyzed data into a format which is different from the original format present in the data set. For example, in a text variable, there are all text values in lowercase, and we want to represent these values in uppercase. Or we need to add decimal places in a variable that contains price information. To do so, SAS provides FORMAT Statement.
The FORMAT statement contains SAS-inbuilt-formats. We can apply the FORMAT statement to use in-built formats and the PROCFORMAT in a user-defined format.
Syntax:
Where,
- FORMAT: It is a FORMAT Statement which indicates the action of formatting.
- Variable name: This is the name of the variable that needs to be formatted.
- Format name: It is the name of SAS-in-built format to be applied on the variable.
Example:
Let’s consider the SAS data set employee containing details of the employees of an organization. Here we need to show the names of employees in uppercase, to do that we are using the FORMAT Statement upcase9, which is SAS-inbuilt-format.
Execute the above code in SAS studio:
Output:
As you can see in the output, all the names of employees have converted into uppercase.
Using PROC FORMAT
PROC FORMAT is used to format user-defined data. We can format data values or observations as per our requirement. In the example given below, we applied both inbuilt and user-defined format statements.
The inbuilt format upcase9 is used to convert lowercase text into uppercase. For user-defined formatting, we changed values of the variable dept from abbreviations to an expanded form, i.e., IT = Information Technology and HR=Human Resources.
Execute the above code in SAS studio:
Output:
As you can see in the output, all names of employees have been converted into uppercase, and abbreviations of the department have been converted into expanded form.