全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
34900 23
2010-11-05
Q1:经常看到data A文件;
set B文件;

这表明创建一个A文件,然后复制B文件中的数据对不?

Q2: 下面一组代码,为什么刚开始要retain y1? retain是用作什么的?
data smart;

retain y1;
if _n_=1 then y=1;else y=2*y1;y1=y;if _n_ =100 then stop;run;谢谢啦~
二维码

扫码加我 拉你入群

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

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

全部回复
2010-11-5 07:58:23
Q1:
data a;
      set b;
run;     

Set的作用是将数据集b中的记录逐条读入PDV中,在run语句的地方SAS会将pdv中的变量输出到数据集a中。
SAS帮助:
What SET DoesEach time the SET statement is executed, SAS reads one observation into the program data vector. SET reads all variables and all observations from the input data sets unless you tell SAS to do otherwise. A SET statement can contain multiple data sets; a DATA step can contain multiple SET statements.


Q2:
RETAIN的作用:The RETAIN statement prevents SAS from re-initializing the values of new variables at the top of the DATA step.
Previous values of retained variables are available for processing across iterations of the DATA step.

对于数据集中新声明的变量,SAS会在data步循环执行开始时将其置为空值,而如果该变量是retain的变量,则不被置空。

还是看个例子:

数据集aaa,有三条记录。
data aaa;
     do x=1,3,5;
     output;
end;
run;

数据集bbb新声明变量y,在读入aaa的第一条记录时将y值设为1. 这样在第二条和第三条记录中y的值为空。

data bbb;
    set aaa;
    if _n_=1 then y=1;
    put _all_;
run;

log:
-----------------------------------------------
x=1 y=1 _ERROR_=0 _N_=1
x=3 y=. _ERROR_=0 _N_=2
x=5 y=. _ERROR_=0 _N_=3
-----------------------------------------------


data步ccc将y声明为retain的变量,在读第一条记录时令y=1,此值会被保留到第二条和第三条记录中。

data ccc;
     set aaa;
     retain y;
  if _n_=1 then y=1;
  put _all_;
run;

log
------------------------------------------
x=1 y=1 _ERROR_=0 _N_=1
x=3 y=1 _ERROR_=0 _N_=2
x=5 y=1 _ERROR_=0 _N_=3
-----------------------------------------


表达比较乱,希望对你有点用处。
二维码

扫码加我 拉你入群

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

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

2010-11-5 09:08:13
赞同2楼的说法
二维码

扫码加我 拉你入群

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

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

2010-11-6 01:27:22
呵呵。如果用mathematica,符号运算,一条命令就搞定了。
二维码

扫码加我 拉你入群

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

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

2012-11-29 14:59:26
谢谢2楼,明白了
二维码

扫码加我 拉你入群

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

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

2012-11-29 16:01:09
学习了~受益了~
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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