全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1164 3
2016-04-19
data a;
input x y;
cards;
1 2
;


data d(rename=(x=xx));
set a (keep=x);
if x=1 then m=10;/**改写成 if xx=1 then m=10; 后,m为空?***/
run;


上面的程序运行后输出如下:
xx   m
1    10


我的问题是如果把带注释的那行改写成 if xx=1 then m=10; 后,为何m变成空了?
到底这些语句的编译顺序是什么呢?

二维码

扫码加我 拉你入群

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

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

全部回复
2016-4-19 01:28:22
/*
data d(rename=(x=xx));
set a (keep=x);
if x=1 then m=10;/**改写成 if xx=1 then m=10; 后,m为空?***/
run;
*/

It is noted that the data step will first read all command you specified within the step
(note that SAS does not read in order by according to importance)

SAS first reads 'set a (keep=x)' to retrieve column x
Then, SAS generates a new variable m because you specify that 'if x=1 then m=10;'
SAS does not know what 'xx' is so far because the variable xx is not yet defined.
Finally, you put this data into dataset d.
When you put this data into d, you then rename x by xx.
Therefore, you could only use 'x' instead of 'xx' as the variable within the data step.
二维码

扫码加我 拉你入群

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

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

2016-4-19 02:51:13
因为 dataset a 里没有变量xx, 所以m 为空.  在你的程序里, rename 是最后执行的.
二维码

扫码加我 拉你入群

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

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

2016-4-19 23:25:32
感谢两位的解答!!!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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