全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1830 2
2018-02-27
DATA tmp;
input ID startmonth price;
cards;
1        198011    12
1        198012    13
1        198101    20
1        198102    25
1        198103    10
1        198104    40
2        201012    3
2        201101    20
2        201102    30
2        201103    5
2        201104    8
;
run;

proc sort data=tmp;
        by ID startmonth;
run;

/**assume data is sorted**/
data tmp2;
do i=0 by 1 until(last.id);
   set tmp;
   by id ;
   output;
   if first.id then max=price;
   if max<price then max=price;
        if first.id then drawback=price/max;
   if price/max<drawback then drawback=price/max;
end;

run;

proc print;run;

我是希望Max和Drawback能够上移一行,我的计算逻辑也是如果第一行,那么直接给max和drawback赋值了,怎么会下移一行,并且第一行出现缺失值呢?怎么解决?谢谢!


附件列表
SAS错位.PNG

原图尺寸 11.56 KB

SAS错位.PNG

二维码

扫码加我 拉你入群

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

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

全部回复
2018-2-28 02:18:48
Put Output Statement on the last.

data tmp2;
do i=0 by 1 until(last.id);
    set tmp;
    by id ;
    if first.id then max=price;
    if max<price then max=price;
         if first.id then drawback=price/max;
    if price/max<drawback then drawback=price/max;
        output;
end;
run;
二维码

扫码加我 拉你入群

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

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

2018-2-28 09:33:23
复制代码
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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