- SAS Tutorial
- SAS - Home
- SAS - Overview
- SAS - Environment
- SAS - User Interface
- SAS - Program Structure
- SAS - Basic Syntax
- SAS - Data Sets
- SAS - Variables
- SAS - Strings
- SAS - Arrays
- SAS - Numeric Formats
- SAS - Operators
- SAS - Loops
- SAS - Decision Making
- SAS - Functions
- SAS - Input Methods
- SAS - Macros
- SAS - Dates & Times
- SAS Data Set Operations
- SAS - Read Raw Data
- SAS - Write Data Sets
- SAS - Concatenate Data Sets
- SAS - Merging Data Sets
- SAS - Subsetting Data Sets
- SAS - Sort Data Sets
- SAS - Format Data Sets
- SAS - SQL
- SAS - Output Delivery System
- SAS - Simulations
- SAS Data Representation
- SAS - Histograms
- SAS - Bar Charts
- SAS - Pie Charts
- SAS - Scatterplots
- SAS - Boxplots
- SAS Basic Statistical Procedure
- SAS - Arithmetic Mean
- SAS - Standard Deviation
- SAS - Frequency Distributions
- SAS - Cross Tabulations
- SAS - T Tests
- SAS - Correlation Analysis
- SAS - Linear Regression
- SAS - Bland-Altman Analysis
- SAS - Chi-Square
- SAS - Fishers Exact Tests
- SAS - Repeated Measure Analysis
- SAS - One-Way Anova
- SAS - Hypothesis Testing
- SAS Useful Resources
- SAS - Quick Guide
- SAS - Useful Resources
- SAS - Questions and Answers
- SAS - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Syntax
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.
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.
d is the number of digits to the right of the decimal.
Reading Numeric formats
Below is a list of formats used for reading the data into SAS.
Input Numeric Formats
Format | Use |
---|---|
n. | Maximum "n" number of columns with no decimal point. |
n.p | Maximum "n" number of columns with "p" decimal points. |
COMMAn.p | Maximum "n" number of columns with "p" decimal places which removes any comma or dollar signs. |
COMMAn.p | Maximum "n" number of columns with "p" decimal places which removes any comma or dollar signs. |
Displaying Numeric formats
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.
Output Numeric Formats
Format | Use |
---|---|
n. | Write maximum "n" number of digits with no decimal point. |
n.p | Write maximum "n.p" number of columns with "p" decimal points. |
DOLLARn.p | 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 greater than the format specifier then the last digit will be rounded off.
Examples
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.