求:给出一个新变量OTB 赋予初始值是1000, OTB+(-AMT),但是当上一个OTB的值小于AMT时,则不计算;仅当上一个OTB的值大于等于AMT时才计算。
求达人支招这个CODE怎么写。多谢了。作者: shiyiming 时间: 2011-7-15 09:02 标题: Re: 求教一个SAS CODE编写问题 [code:2t7r4tp0]data want_set;
set your_set;
retain otb 1000;
if otb ge amt then otb=otb-amt;
run;
[/code:2t7r4tp0]作者: shiyiming 时间: 2011-7-18 21:38 标题: Re: 求教一个SAS CODE编写问题 高手兄,谢谢了。
不过还要请教下,如果再多一个变量,按NAME、DATE排序,再同样计算的CODE怎么写?先谢谢了!
NAME DATE AMT OTB
LI 1 200 1000-200
LI 2 200 800-200
LI 3 300 600-300
LI 4 600 300
LI 5 500 300
LI 6 200 300-200
SMITH 1 200 1000-200
SMITH 2 200 800-200
SMITH 3 300 600-300
SMITH 4 600 300
SMITH 5 500 300
SMITH 6 200 300-200作者: shiyiming 时间: 2011-7-18 21:57 标题: Re: 求教一个SAS CODE编写问题 [code:27cscfsg]data yours;
input name $ date amt;
cards;
LI 1 200 1000-200
LI 2 200 800-200
LI 3 300 600-300
LI 4 600 300
LI 5 500 300
LI 6 200 300-200
SMITH 1 200 1000-200
SMITH 2 200 800-200
SMITH 3 300 600-300
SMITH 4 600 300
SMITH 5 500 300
SMITH 6 200 300-200
;
data want_set;
set yours;
by name date notsorted;
retain otb;
if first.name then otb=1000;
if otb ge amt then otb=otb-amt;
output;
run;[/code:27cscfsg]作者: shiyiming 时间: 2011-7-19 19:48 标题: Re: 求教一个SAS CODE编写问题 如果OTB的开始值每个都不一样,比如下面,让OTB都从amt_b的值开始减,这样怎么写?
data yours;
input name $ date amt amt_b;
cards;
LI 1 200 1000
LI 2 200 1000
LI 3 300 1000
LI 4 600 1000
LI 5 500 1000
LI 6 200 1000
SMITH 1 200 800
SMITH 2 200 800
SMITH 3 300 800
SMITH 4 600 800
SMITH 5 500 800
SMITH 6 200 800
;作者: shiyiming 时间: 2011-7-19 21:19 标题: Re: 求教一个SAS CODE编写问题 [code:2p8mkh6u]
data result;
set yours;
by name date notsorted;
if first.name then otb=amt_b;
if otb>=amt then otb+(-amt);
run;
[/code:2p8mkh6u]作者: shiyiming 时间: 2011-7-20 04:59 标题: Re: 求教一个SAS CODE编写问题 I am really lost, how to read this kind of data:
DATE AMT OTB
1 200 1000-200
what dose '1000-200' mean? Is this one of OTB value?作者: shiyiming 时间: 2011-7-20 06:20 标题: Re: 求教一个SAS CODE编写问题 I think he just wants to show how to calculate the value. JingJu作者: shiyiming 时间: 2011-7-20 22:47 标题: Re: 求教一个SAS CODE编写问题 我的问题解决了,多谢大侠!