|
建议用Formatted Input 的时候加上 ":" modifier, 这样就不会受到@或@@的影响。
data a;
input sb : $11. p : $9. startdate : yymmdd10. enddate : yymmdd10.@;
cards;
13404800000 47117001 20060401 20070401
13404800007 40017100 20060501 20080401
13404800012 47104049 20061219 20080301
13404800014 47104049 20061208 20070801
13404800016 40013004 20061230 20070501
13404800020 47104049 20060630 20070901
;
run;
当Formatted Input和@@一起用时,就会产生意外的结果:
data b;
input sb $11. p $9. startdate yymmdd10. enddate yymmdd10.@@;
format startdate enddate yymmdd10.;
cards;
13404800000 47117001 20060401 20070401
13404800007 40017100 20060501 20080401
13404800012 47104049 20061219 20080301
13404800014 47104049 20061208 20070801
13404800016 40013004 20061230 20070501
13404800020 47104049 20060630 20070901
;
run;
Log:
821 data b;
822 input sb $11. p $9. startdate yymmdd10. enddate yymmdd10.@@;
823 format startdate enddate yymmdd10.;
824 cards;
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.B has 12 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds
831 ;
832 run;
又如下面例子:
data c;
input c $40. @@;
datalines;
1---shorter than 80---end
;
data c1;
input c $40. @@;
datalines;
1---shorter than 80---end
2---longer than 80----------------------------------------------but shorter than 160---end
3---shorter than 80---end
4---shorter than 80---end
;
Log:
937 data c;
938 input c $40. @@;
939 datalines;
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.C has 2 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds
941 ;
942 data c1;
943 input c $40. @@;
944 datalines;
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.C1 has 14 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds
949 ;
初看程序,预计数据集C中会有1条记录,数据集C1中会有5条记录,而结果却不是这样。
个人猜测:当用datalines/cards读取数据时,
1. SAS会在每一行的数据后加空格(或类似字符)知道80的倍数;
Data c1; 数据步中,第一行会补到80个字符,第二行会补到160
2. 下一行数据(补空格后)的长度不会小于上一行数据;
Data c1;数据步中,第三行虽然短于80,仍然补到了160个字符。
个人拙见,凭空猜测。查SAS帮助未果,望高手解惑!
|