【发布时间】:2016-05-31 11:59:55
【问题描述】:
作为第一次查看 SAS 代码的 SQL 开发人员,我很难理解提供给我的脚本的一部分。
请任何人解释以下内容的作用,或者如果可能的话,SQL 中的等价物?
* sum up the total 6 months value for customers with positive value and quantity of items;
proc summary data=value_last6_positive nway missing;
var saleprice quantity;
class Cardid ;
output out = value_last6_s (drop=_type_ _freq_)
sum(saleprice)=saleprice
sum(quantity)=quantity;
run;
* rank them;
proc sort data=value_last6_s;
by saleprice;
run;
data count;
set value_last6_s;
count=1;
run;
proc sort data=count;
by count;
run;
data count2;
set count;
by count;
if first.count then rank=1;
else rank+1;
if rank=<544139 then decile=10;
else if rank=<544139*2 then decile=9;
else if rank=<544139*3 then decile=8;
else if rank=<544139*4 then decile=7;
else if rank=<544139*5 then decile=6;
else if rank=<544139*6 then decile=5;
else if rank=<544139*7 then decile=4;
else if rank=<544139*8 then decile=3;
else if rank=<544139*9 then decile=2;
else decile=1;
run;
proc freq data=count2;
table decile;
run;
proc means data=count2;
var saleprice;
class decile;
run;
我已经构建了一个等效于value_last6_s 的临时表,它的结构为(CardID, SalePrice, Quantity),使用按CardID 分组的销售数据聚合。不太确定如何进行。提前致谢。
编辑:
我的第一个proc summary块的转换:
-- value_last6_s
SELECT CardID,
SUM(SalePrice) SalePrice,
SUM(Quantity) Quantity
INTO #value_last6_s
FROM #value_last6_positive
GROUP BY CardID
ORDER BY SUM(SalePrice);
【问题讨论】:
-
我不能确定,但我认为它总结了具有正值和物品数量的客户的 6 个月总价值......
-
@RQDQ 谢谢,非常有帮助。
-
对不起 - 我无法抗拒。 :-) 到目前为止,您开发了哪些 SQL?
-
我已经转换到 sn-p 的开头,包括
proc summary块。我会把它包括在问题中。 -
我不确定 SAS 代码是否正确或是否符合其应有的目的......关于功能要求的任何想法?
标签: sql sql-server sas