Sas 简明教程
SAS - Numeric Formats
SAS 可以处理多种数值数据格式。它在变量名称的末尾使用这些格式,将特定的数值格式应用到数据。SAS 使用两种数值格式。一种用于读取称为 informat 的数值数据的特定格式,另一种用于以称为 output format 的特定格式显示数值数据。
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
以下是用于将数据读入 SAS 的格式列表。
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
与在读取数据时应用格式类似,以下是用于在 SAS 程序的输出中显示数据的格式列表。
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 then*zeros 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.