如果有数据步骤:
data myRegions;
set myRegions;
ext_price = price * qty;
mix = weighted_calc * ext_price;
run;
我想在SQL上执行此操作,因为我想使用一些分组和子查询
但每次我想使用该值时,我是否都要进行price * qty
操作?!
答案 0 :(得分:4)
您可以使用文档中的calculated:
CALCULATED使您可以使用表达式的结果 SELECT子句或WHERE子句。它仅在习惯时有效 引用在立即查询中计算的列 表达
以下是一个例子:
proc sql;
create table myRegions as
Select a.*,
(price * qty) as ext_price ,
(weighted_calc * calculated ext_price ) as mix
from myRegions;
quit;