- SAS - Dates & Times
- SAS - Macros
- SAS - Input Methods
- SAS - Functions
- SAS - Decision Making
- SAS - Loops
- SAS - Operators
- SAS - Numeric Formats
- SAS - Arrays
- SAS - Strings
- SAS - Variables
- SAS - Data Sets
- SAS - Basic Syntax
- SAS - Program Structure
- SAS - User Interface
- SAS - Environment
- SAS - Overview
- SAS - Home
SAS Data Set Operations
- SAS - Simulations
- SAS - Output Delivery System
- SAS - SQL
- SAS - Format Data Sets
- SAS - Sort Data Sets
- SAS - Subsetting Data Sets
- SAS - Merging Data Sets
- SAS - Concatenate Data Sets
- SAS - Write Data Sets
- SAS - Read Raw Data
SAS Data Representation
SAS Basic Statistical Procedure
- SAS - Hypothesis Testing
- SAS - One-Way Anova
- SAS - Repeated Measure Analysis
- SAS - Fishers Exact Tests
- SAS - Chi-Square
- SAS - Bland-Altman Analysis
- SAS - Linear Regression
- SAS - Correlation Analysis
- SAS - T Tests
- SAS - Cross Tabulations
- SAS - Frequency Distributions
- SAS - Standard Deviation
- SAS - Arithmetic Mean
SAS Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
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 appped 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 pst 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 pst 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; datapnes; 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; datapnes; 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; datapnes; 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.Advertisements