我有这个规范来导出参数代码DACAPNT的AVAL。

对于红色高亮显示的文本,这是我试图使用的代码
*Performing calculations for DACAPNT AVAL *;
proc sql;
create table sum_by_totda as
select *
,sum(dastresn) as totn
from sdtm.da
where datestcd in ("RETAMT","DISPAMT")
group by usubjid, datestcd
;
quit;我的问题是,是否有办法在这个PROC SQL语句中进行计算,或者这是否需要额外的数据步骤/PROC SQL?
发布于 2022-09-04 23:12:33
您可以在SQL中的聚合函数中包括CASE/WHEN/CASE/END逻辑,因此可以使用以下方法实现这一点:
sum(case when paramcd = 'CAPSEXP' then aval else 0 end +
case when datestcd = 'RETAMT' then dastresn else 0 end +
case when datestcd = 'DISPAMT' then -1*dastresn else 0 end)https://stackoverflow.com/questions/73581399
复制相似问题