May 27, 2021 SAS
Sometimes we prefer to display the analyzed data in a format that is different from what already exists in the dataset. F or example, we want to add a dollar sign and two decimal places to a variable with price information. O r we might want to display a text variable, all capital. W e can use FORM to apply the built-in SAS format, proC FORMAT is the user-defined format for the application. I n addition, a single format can be applied to multiple variables.
The basic syntax for applying the built-in SAS format is:
format variable name format name
The following is a description of the parameters used:
Let's consider the following SAS dataset that contains employee details for your organization. W e want all names to be displayed in capitals. F ormat statements to achieve this.
DATA Employee; INPUT empid name $ salary DEPT $ ; format name $upcase9. ; DATALINES; 1 Rick 623.3 IT 2 Dan 515.2 OPS 3 Mike 611.5 IT 4 Ryan 729.1 HR 5 Gary 843.25 FIN 6 Tusar 578.6 IT 7 Pranab 632.8 OPS 8 Rasmi 722.5 FIN ; RUN; PROC PRINT DATA=Employee; RUN;
When executing the above code, we can get the following output.
We can also use PROC FORMAT to format the data. I n the following example, we assign the new value to the variable DEPT of the department name.
DATA Employee; INPUT empid name $ salary DEPT $ ; DATALINES; 1 Rick 623.3 IT 2 Dan 515.2 OPS 3 Mike 611.5 IT 4 Ryan 729.1 HR 5 Gary 843.25 FIN 6 Tusar 578.6 IT 7 Pranab 632.8 OPS 8 Rasmi 722.5 FIN ; proc format; value $DEP 'IT' = 'Information Technology' 'OPS'= 'Operations' ; RUN; PROC PRINT DATA=Employee; format name $upcase9. DEPT $DEP.; RUN;
When executing the above code, we can get the following output.