SAS - Numeric Formats

SAS can handle a wide variety of numeric data formats. It uses these formats at the end of the variable names to apply a specific numeric format to the data. SAS use two kinds of numeric formats. One for reading specific formats of the numeric data which is called informat and another for displaying the numeric data in specific format called as output format.
The Syntax for a numeric informat is −
Varname Formatnamew.d

Following is the description of the parameters used −
Varname is the name of the variable.
Varname is the name of the variable.
Formatname is the name of the name of the numeric format applied to the variable.
Formatname is the name of the name of the numeric format applied to the variable.
w is the maximum number of data columns (including digits after decimal & the decimal point itself) allowed to be stored for the variable.
w is the maximum number of data columns (including digits after decimal & the decimal point itself) allowed to be stored for the variable.
d is the number of digits to the right of the decimal.
d is the number of digits to the right of the decimal.
Below is a list of formats used for reading the data into SAS.
Maximum "n" number of columns with no decimal point.
Maximum "n" number of columns with "p" decimal points.
Maximum "n" number of columns with "p" decimal places which removes any comma or dollar signs.
Maximum "n" number of columns with "p" decimal places which removes any comma or dollar signs.
Similar to applying format while reading the data, below is a list of formats used for displaying the data in the output of a SAS program.

Write maximum "n" number of digits with no decimal point.
Write maximum "n.p" number of columns with "p" decimal points.
Write maximum "n" number of columns with p decimal places, leading dollar sign and a comma at the thousandth place.
Please Note −
If the number of digits after the decimal point is less than the format specifier thenzeros will be appended at the end.
If the number of digits after the decimal point is less than the format specifier thenzeros will be appended at the end.
If the number of digits after the decimal point is greater than the format specifier then the last digit will be rounded off.
If the number of digits after the decimal point is greater than the format specifier then the last digit will be rounded off.
Below examples illustrate above scenarios.
DATA MYDATA1;
input x 6.; /*maxiiuum width of the data*/
format x 6.3;
datalines;
8722
93.2
.1122
15.116
PROC PRINT DATA = MYDATA1;
RUN;

DATA MYDATA2;
input x 6.; /*maximum width of the data*/
format x 5.2;
datalines;
8722
93.2
.1122
15.116
PROC PRINT DATA = MYDATA2;
RUN;
DATA MYDATA3;
input x 6.; /*maximum width of the data*/
format x DOLLAR10.2;
datalines;
8722
93.2
.1122
15.116
PROC PRINT DATA = MYDATA3;
RUN;

When we execute above code, it produces following result −
# MYDATA1.
Obs 	x
1 	8722.0 # Display 6 columns with zero appended after decimal.
2 	93.200 # Display 6 columns with zero appended after decimal.
3 	0.112  # No integers before decimal, so display 3 available digits after decimal.
4 	15.116 # Display 6 columns with 3 available digits after decimal.

# MYDATA2
Obs 	x
1 	8722  # Display 5 columns. Only 4 are available.
2 	93.20 # Display 5 columns with zero appended after decimal.
3 	0.11  # Display 5 columns with 2 places after decimal.
4 	15.12 # Display 5 columns with 2 places after decimal.

# MYDATA3
Obs 	x
1 	$8,722.00 # Display 10 columns with leading $ sign, comma at thousandth place and zeros appended after decimal.
2 	$93.20    # Only 2 integers available before decimal and one available after the decimal.
3 	$0.11	  # No integers available before decimal and two available after the decimal.
4 	$15.12    # Only 2 integers available before decimal and two available after the decimal.

    50 Lectures 
     5.5 hours 

 Code And Create

    124 Lectures 
     30 hours 

 Juan Galvan

    162 Lectures 
     31.5 hours 

 Yossef Ayman Zedan

    35 Lectures 
     2.5 hours 

 Ermin Dedic

    167 Lectures 
     45.5 hours 

 Muslim Helalee
 Print
 Add Notes
 Bookmark this page