楼主: saximi
1206 3

[问答] 请教语句的编译顺序问题 [推广有奖]

  • 0关注
  • 0粉丝

高中生

90%

还不是VIP/贵宾

-

威望
0
论坛币
420 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
6511 点
帖子
29
精华
0
在线时间
16 小时
注册时间
2012-11-15
最后登录
2016-6-13

楼主
saximi 发表于 2016-4-19 00:19:53 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
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变成空了?
到底这些语句的编译顺序是什么呢?

二维码

扫码加我 拉你入群

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

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

关键词:rename cards Input Then Data 程序

沙发
kimiseebo 发表于 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.

藤椅
yingzi2003 发表于 2016-4-19 02:51:13
因为 dataset a 里没有变量xx, 所以m 为空.  在你的程序里, rename 是最后执行的.

板凳
saximi 发表于 2016-4-19 23:25:32
感谢两位的解答!!!

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-21 22:37