菜鸟今天才开始看the little sas book!看到下面这个程序。弄出来和大家分享一下,有什么说的不对的地方,各位大神多多指教!
在SAS中运行如下程序,查看结果。
data test;
infile cards ;
input x @;
input y;
input z @@;
cards;
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17
;
run;
proc print;
run;
结果:
Obs x y z
1 1 2 7
2 8 9 13
我自己的体验解释:
一个data步读取数据是多个循环构成的。
一个input语句执行完之后立即换行继续下面的语句;
若在input语句之后加@,则该行以及之后的数据保留到下一个input语句开始读入数据;
若在input语句之后加@@,则该行以及之后的数据保留到下一次data步循环。
可以对比:
data test;
infile cards ;
input x @;
input y;
input z @;
cards;
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17
;
run;
proc print;
run;
结果:
Obs x y z
1 1 2 7
以及:
data test;
infile cards ;
input x @;
input y;
input z ;
cards;
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17
;
run;
proc print;
run;
结果:
Obs x y z
1 1 2 7
还可以添加 pull _all_ 查看变量的取值过程:
data test;
infile cards ;
put _all_;
input x @;
put _all_;
input y;
put _all_;
input z @;
put _all_;
cards;
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17
;
run;
proc print;
run;