SAS中文论坛

标题: sas程序学习中的一个小问题 [打印本页]

作者: shiyiming    时间: 2008-4-22 18:17
标题: sas程序学习中的一个小问题
这是汪嘉冈书上275页的例6.5, 我自己去试了有个小问题.:
以下如果缺少语句"by dept", 整个程序将不打印任何东西. 也就是,temp2里面没有任何观测值.为什么?
以下是程序.
/****************************************************************************************************/
data temp1;
input idnum $ name $12. dept $ wagecat $ wagerate;
cards;
1351 Farr, Sue   ADM20 S 3392.50
161  Cox, Kay B  ADM30 S 5093.75
212  Moore, Ron  CAM10 S 1813.30
2512 Ruth. G H   CAM10 S 1572.50
2532 Hobbs, Roy  CAM10 H 13.48
282  Shaw, Rick  ADM30 S 2192.25
3131 Gant, Amy   ADM30 H 13.50
341  Mann, Mary  CAM20 H 13.55
3551 Cobb, Joy F ADM20 H 13.65
3782 Bond, Jim S ADM20 S 2247.50
;
run;
proc sort data=temp1;
by dept;
run;
data temp2(keep=dept payroll);
set work.temp1;
[color=#FF4000:wpulebn2]by dept;[/color:wpulebn2]
/************if the sentence "by dept" is missing, and if you submit this program then nothing will come out in the output window.******/
if wagecat='S' then wagerate_new=wagerate*12;
if wagecat='H' then wagerate_new=wagerate*2000;
if first.dept then payroll=0;
payroll+wagerate_new;
if last.dept;
proc print data=temp2;
run;
/***********************************************************************************/
作者: shiyiming    时间: 2008-4-23 00:32
标题: Re: sas程序学习中的一个小问题
The  reason it has to have a by dept statement is because there are first.dept and last.dept statements follow.
It's just like you have to sort you data before you run the proc freq.

by dept;

if first.dept then payroll=0;

if last.dept;

Hope this help.

YZ




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2