作爲一名首次查看SAS代碼的SQL開發人員,我很努力地理解我提供的一段腳本。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
分組銷售數據的聚集結構(CardID, SalePrice, Quantity)
了。不確定如何繼續。提前致謝。
編輯:
我的第一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);
我不能肯定,但我認爲它總結爲客戶提供正值和物品的數量... – RQDQ
@RQDQ謝謝,非常有幫助的總共6個月的值。 –
對不起 - 我無法抗拒。 :-)到目前爲止,你開發了哪些SQL? – RQDQ