Numeric Data FormatSAS can handle different types of numeric data formats. These formats are used at the end of the variable name to apply a specific numeric format to the data. SAS uses two types of numeric formats, one is informat, and another is output format. Where an informat is a specification of how SAS should read data, and an output format is a layout specification of how a variable should be displayed in the output. There are many internal informats and output formats in SAS. Or userdefined informats and output formats can be created by using PROC FORMAT. The list of all internal informats and output formats can be seen by typing 'help format' in the command line and then clicking 'SAS Format and Informat' in the resulting window. Let's understand the following terms of numeric formats in detail:
InformatSAS informat is a part of the SAS Numeric Format, specifies how SAS reads a particular data. These are specified in the INPUT statement. Always place a decimal (.) at the end of the informat because SAS uses this decimal (.) to separates informat from other variables. The informat instructs SAS, how to read data into SAS variables. Following is a list of informats which are used to read the data into SAS. Input Numeric Informat
How SAS Reads Numeric Informat?SAS Numeric Informat consists of two components one is Number of Columns in output, and another is Number of Decimal Places. The SAS system is based on floatingpoint representation referred to as W.D to read the numeric informat. In W.D, W is the number of columns, and D is the number of digits on the right of the decimal place. For example, if the value of W.D is 7.2, then it will allocate a total of 7 spaces for the output. Four spaces will be allocated for the left side digits of the decimal, one space for the decimal and remaining two for the right side digits of the decimal. In the following table, numeric data 2789.93 is demonstrated by using 7.2 informat. It demonstrates how the allocation of digits takes place in the SAS system by using W.D informat.
We can use W.D informat in SAS programs by using the following Syntax: Where,
Example:Execute the above code in SAS Studio: Output: As we can see in the output, SAS is following W.D informat to store numeric values. Here the value of W.D is 10.2, which means that SAS reads a total of 10 spaces. It allocates 7 spaces for the digits that are left the side of the decimal, 1 space for the decimal and remaining 2 for the digits that are the right side of the decimal. Output FormatSAS Output Format is used to instruct the SAS to display data in the desired format in the output. It is another part of the SAS numeric format. We can display numeric values in three formats:
Simple W.D formatIt is the basic reading, and also an output format of SAS, where W is the number of columns and D is the number of digits on the right side of the decimal place. Let's understand through an example, how we can display data by using W.D format. Example: Execute the above code in SAS Studio: Output: As we can see in the output, SAS is using W.D informat to store numeric values. Here the value of W.D is 10.2, which means SAS reads a total of 10 spaces. It allocates 7 spaces for the left side digits of the decimal, 1 space for the decimal and remaining 2 for the right side digits of the decimal. DollarW.D format:This format is used when we need to add a dollar sign with numerical data. Let's understand through an example, how we can use DollarW.D format. Example: If there is a numerical variable named salary in the dataset, then due to its numerical data type, there is a possibility of decimal places in this variable. So, let's consider the salary of employees of an organization which is mentioned without currency sign, e.g., 475.301. Now, employees want to see this salary in terms of dollars. To do so, we need to place a dollar sign with it. In order to do that, we need to instruct SAS to use DollarW.D format. Execute the above code in SAS Studio: Output: As we can see in the output, the salary has been displayed with a dollar sign. CommaW.D formatThis format is used when we need to add a comma to separate the digits of numerical data to get a better understanding. Let's understand through an example, how we can use CommaW.D format. Execute the above code in SAS Studio: Output: As we can see in the output, variable salary has been displayed with commas.
Next TopicSAS Loop
