s*****p 发帖数: 299 | 1 data Work.Total_Salary;
retain Total;
set Work.Salary;
by Department;
if First.Department
then total=0;
Total=sum(Total,Wagerate);
if Last.Total;
run;
what is the initial value of the variable Total?
Answer:Missing
为什么会是这个答案呢?我一直都以为是0。
哪位大侠能帮我扫扫retain的盲,一直对这个命令很疑惑。
多谢!! |
d*******o 发帖数: 493 | 2 这个是经典的Data step classified aggregation . 用SQL写是
proc sql;
create table Total_Salary as
select sum(Wagerate) as total,department
from Salary
group by department
;quit;
Retain before by Set statement can be 'missing' or 'zero'. |
s*****p 发帖数: 299 | 3 Retain before by Set statement can be 'missing' or 'zero'.
能具体说说什么时候是missing什么时候是zero吗?
谢谢! |
s*****p 发帖数: 299 | 4 data Work.Total_Salary;
retain Total;
set Work.Salary;
by Department;
if First.Department
then total=0;
Total=sum(Total,Wagerate);
if Last.Total;
run;
what is the initial value of the variable Total?
Answer:Missing
为什么会是这个答案呢?我一直都以为是0。
哪位大侠能帮我扫扫retain的盲,一直对这个命令很疑惑。
多谢!! |
d*******o 发帖数: 493 | 5 这个是经典的Data step classified aggregation . 用SQL写是
proc sql;
create table Total_Salary as
select sum(Wagerate) as total,department
from Salary
group by department
;quit;
Retain before by Set statement can be 'missing' or 'zero'. |
s*****p 发帖数: 299 | 6 Retain before by Set statement can be 'missing' or 'zero'.
能具体说说什么时候是missing什么时候是zero吗?
谢谢! |
s********1 发帖数: 54 | 7
Do you think the correct code should be "if Last.Department;" rather than "
if Last.Total;"? Thank you!!!!
【在 s*****p 的大作中提到】 : data Work.Total_Salary; : retain Total; : set Work.Salary; : by Department; : if First.Department : then total=0; : Total=sum(Total,Wagerate); : if Last.Total; : run; : what is the initial value of the variable Total?
|
w********y 发帖数: 371 | 8 retain total;
如果不给初值,就是missing |
s********1 发帖数: 54 | 9 Yes, I know what you said. But note that first.total and last.total should
be applied with by total statement. Since the question has "by Department",
I think it should be last.Department rather than last.total. Also, the
question never states by total.
Thanks!!!
【在 w********y 的大作中提到】 : retain total; : 如果不给初值,就是missing
|