楼主: timedodo
2633 0

SAS:输入输出格式 $VARYINGw. Informat [推广有奖]

  • 0关注
  • 0粉丝

本科生

4%

还不是VIP/贵宾

-

威望
0
论坛币
95 个
通用积分
0
学术水平
2 点
热心指数
6 点
信用等级
1 点
经验
3960 点
帖子
53
精华
0
在线时间
49 小时
注册时间
2009-8-17
最后登录
2011-6-27

楼主
timedodo 发表于 2011-1-6 11:54:02 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
用途:
用于读入长度不一的字符记录


Details


Use $VARYINGw. when the length of a character value differs from record to record. After reading a data value with $VARYINGw., the pointer's position is set to the first column after the value.



案例:

Example 1: Obtaining a Current Record Length Directly
  1. input fwidth 1. name $varying9. fwidth;
复制代码
Data LineResults
----+----1
5sharkshark
3sunfishsun
8bluefishbluefish
* Notice the result of reading the second data line.




Example 2: Obtaining a Record Length Indirectly Use the LENGTH= option in the INFILE statement to obtain a record length indirectly. The input data lines and results follow the explanation of the SAS statements.
  1. data one;
  2. infile file-specification length=reclen; input @;
  3. fwidth=reclen-9;
  4. input name $ 1-9 @10 class $varying20. fwidth;
  5. run;
复制代码
The LENGTH= option in the INFILE statement assigns the internally stored record length to RECLEN when the first INPUT statement executes. The trailing @ holds the record for another INPUT statement. Next, the assignment statement calculates the value of the varying-length field by subtracting the fixed-length portion of the record from the total record length. The variable FWIDTH contains the length of the last field and becomes the length-variable argument to the $VARYING20. informat.


Data LineResults
----+----1----+----2
PATEL    CHEMISTRYPATEL    CHEMISTRY
JOHNSON  GEOLOGYJOHNSON  GEOLOGY
WILCOX   ARTWILCOX   ART



用法:

$VARYINGw. length-variable


Syntax Description
w    指定字符变量的最大宽度

specifies the maximum width of a character field for all the records in an input file.

Default:8 if the length of the variable is undefined; otherwise, the length of the variable
Range:1-32767

length-variable  指定一个数值变量作为前面要读入的字符变量的宽度
specifies a numeric variable that contains the width of the character field in the current record. SAS obtains the value of length-variable by reading it directly from a field that is described in an INPUT statement or by calculating its value in the DATA step.

Requirement:You must specify length-variable immediately after $VARYINGw. in an INPUT statement.
Restriction:Length-variable cannot be an array reference.
Tip:If the value of length-variable is 0, negative, or missing, SAS reads no data from the corresponding record. A value of 0 for length-variable enables you to read zero-length records and fields. If length-variable is greater than 0 but less than w, SAS reads the number of columns that are specified by length-variable. Then SAS pads the value with trailing blanks up to the maximum width that is assigned to the variable. If length-variable is greater than or equal to w, SAS reads w columns.

详细参考出处:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000193602.htm
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:VARYINGw informat informa varying inform informat VARYINGw

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2025-12-9 15:27