全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2866 2
2009-07-25
在一个infile 的data步里,出现一些if语句,并且有多个地方有input,但整个步骤中没有output语句,这个时候什么时候才是写一条记录进去呢?
或者帮忙解释一下下面这个program是怎么执行的.谢谢!

data sasuser.billing1 (drop=type);   
infile jan98dat;   
retain ID Name;  
input Type $1. @;   
if type='P' then input @3 id $4. @8 name $15.;  
if type='C';   
input @3 Date mmddyy8. @12 Amount comma6.;
  format date mmddyy8. amount dollar7.2;
run;
proc print data=sasuser.billing1;
run;

jan98dat的前5条记录是
Raw Data File Jan98dat
1---+----10---+----20--
P 1095 SMITH, HOWARD
C 01-08-98 $45.0
C 01-17-98 $37.5
P 1096 BARCLAY, NICK
C 01-09-98 $156.5  

  这个程序实际运行的结果是
obs      id        name                     date               amount
1        1096   smith,howard      01/09/98           $45.00
2        1096   smith,howard      01/17/98          $37.50
剩下的记录和这个差不多。  我的疑问是,为什么不是第一个input的时候就output了。这个output的机制到底是怎么样的? 请高手赐教,谢谢!
另外就是最后出现的if type='C'; 语句是怎么执行的?如果是否是什么情况。
二维码

扫码加我 拉你入群

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

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

全部回复
2009-7-26 00:48:35
首先这个raw data文件是hierarchical file,也就是说type为P的记录是head record,后面的每一个type为C的记录属于对应的上面的type为P的记录。

因为你不自己输入output的话data语句是执行一次output一次的,所以不是第一个input的时候就output了。

if type='C';这个语句表面接下来的语句只有在该语句为真的情况下才执行,如果是否的话后面的就不读取date和amount这两个变量的数值了。
二维码

扫码加我 拉你入群

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

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

2009-7-26 09:20:09
谢谢你的解释。
我用sas的online doc,查了一下data step,发现这2行。
subsetting IF statement stops the current iteration when a condition is false, does not write the current observation to the data set, and returns control to the top of the DATA step.

IF-THEN/ELSE statement stops the current iteration when a condition is true, writes the current observation to the data set, and returns control to the top of the DATA step.

发现还是不对劲,这样的话第一个关于type的if,应该在值等于p的时候就跳到top ot the data step了,这是咋回事呢?
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群