Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

SAS digital format


May 26, 2021 SAS


Table of contents


SAS can handle a variety of digital data formats. I t uses these formats at the end of the variable name to apply a specific number format to the data. S AS uses two numeric formats. O ne is used to read a specific format for digital data, called informat, and the other is used to display digital data in a specific format called an output format.

Syntactic

The syntax of digital information is:

Varname Formatnamew.d

The following is a description of the parameters used:

  • VARNAME is the name of the variable.
  • FORMATNAME is the name of the numeric format applied to the variable.
  • w is the maximum number of columns of data that are allowed to be stored for variables, including the number after the number of points and the number of points themselves.
  • d is the number of digits to the right of the scale.

Read the number format

Below is a list of formats used to read data into SAS.

Enter the number format

Format Use
N.
The maximum "n" number of columns without a few points.
n.p
The maximum number of columns with "n" and "p" dosdles.
COMMAn.p COMMAn.p Max "n" columns with "p" places, remove any commas or dollar signs.
COMMAn.p COMMAn.p Max "n" columns with "p" places, remove any commas or dollar signs.

Displays the number format

Similar to applying formats when reading data, the following is a list of formats used to display data in the output of the SAS program.

Output the number format

N.
Write the maximum "n" digits without a scale.
n.p
Write the maximum number of columns with a "p" dosdle of "n.p".
DOLLARn.p
Write the maximum "n" column with the p decimal place, preceded by the dollar sign, and use a comma at the thousandth position.

Please note:

  • If the number of digits after the scale is less than the format descriptor, attach zero at the end .
  • If the number of digits after the scale is greater than the format descriptor, the last digit is rounded.

Example

The following example illustrates the above.

DATA MYDATA1;
input x 6.; /*数据的最大宽度*/
format x 6.3;
datalines;
8722
93.2
.1122
15.116
PROC PRINT DATA = MYDATA1;
RUN;

DATA MYDATA2;
input x 6.; /*数据的最大宽度*/
format x 5.2;
datalines;
8722
93.2
.1122
15.116
PROC PRINT DATA=MYDATA2;
RUN;
DATA MYDATA3;
input x 6.; /*数据的最大宽度*/
format x DOLLAR10.2;
datalines;
8722
93.2
.1122
15.116
PROC PRINT DATA=MYDATA3;
RUN;

When we execute the code above, it produces the following results:

# MYDATA1.
Obs 	x
1 	8722.0 # 显示6个十进制后附加零的列。
2 	93.200 # 显示6个小数后附加零的列。
3 	0.112  # 十进制之前没有整数,因此在十进制后显示3个可用数字。
4 	15.116 # 显示6个十进制后有3位可用数字的列。

# MYDATA2
Obs 	x
1 	8722  # 显示5列。 只有4个可用。
2 	93.20 # 显示5个十进制后附加零的列。
3 	0.11  # 显示5个小数点后2位的列。
4 	15.12 # 显示5个小数点后2位的列。

# MYDATA3
Obs 	x
1 	$8,722.00 # 显示10列带有$符号,逗号在第千个位置,零在十进制后附加。
2 	$93.20    # 只有两个整数在十进制之前可用,一个可用在十进制之后。
3 	$0.11	  # 十进制之前没有整数,十进制后有两个可用。
4 	$15.12    # 只有两个整数在十进制之前可用,两个可用在十进制之后。