我有以下数据集:
Row - Customer - Renew Date - Type of Renewal - Days
1 - A - June 10, 2010 - X
2 - A - May 01, 2011 - Y
3 - B - Jan 05, 2010 - Y
4 - B - Dec 10, 2010 - Z
5 - B - Dec 10, 2011 - X 有没有办法在查询构建器中添加一个条件,从每个客户的第2行中减去第1行,这样我就可以得到“天数”,在此之后,客户续订了他们的会员资格?
基本上,我需要帮助减少查询构建器中的行。
请快点。
发布于 2013-07-04 04:12:42
如果你写一个datastep,这并不太难。我不知道这在Query Builder中是不是很容易做到。
data have;
informat renew_date ANYDTDTE.;
format renew_date DATE9.;
infile datalines dlm='-';
input Row Customer $ Renew_Date Renewal_Type $;
datalines;
1 - A - June 10, 2010 - X
2 - A - May 01, 2011 - Y
3 - B - Jan 05, 2010 - Y
4 - B - Dec 10, 2010 - Z
5 - B - Dec 10, 2011 - X
;;;;
run;
data want;
set have;
by customer;
retain prev_days; *retain the value of prev_days from one row to the next;
if first.customer then days_since=0; *initialize days_since to zero for each customer's first record;
else days_since=renew_date-prev_days; *otherwise set it to the difference;
output; *output the current record;
prev_days=renew_date; *now change prev_days to the renewal date so the next record has it;
run;https://stackoverflow.com/questions/17456452
复制相似问题