datatable - Dividing within a column based on other columns matching
问题描述
I am trying to calculate the current measurement in column “Total" minus the lowest measurement previously recorded in column "Total" where the current measurement in column “Total” corresponding to the value in column "Trade" is less than(<) the minimum measurement in column “Total” corresponding to the value in column "trade", and if two values in the “SUBJECT” column match and two values in the “PROCEDURE” column match. To emphasize, the minimum value must be a previously recorded. If the measurement is less than the current measurement but was not recorded previously (according to the “date” column), it does not quality to be subtracted from the current measurement. An example of the output is provided below.
data Have;
input Subject Type :$12. Date &:anydtdte. Trade Procedure :$12. Measurement;
format date yymmdd10.;
datalines;
Subject Type Date Trade Procedure Total
500 Initial 15 AUG 2017 6 Invasive 20
500 Initial 15 AUG 2017 9 Surface 35
500 Followup 15 AUG 2018 8 Invasive 54
428 Followup 15 AUG 2018 56 Outer 29
765 Seventh 3 AUG 2018 12 Other 13
500 Followup 3 JUL 2018 23 surface 98
428 Initial 3 JUL 2017 34 Outer 10
765 Initial 20 JUL 2019 4 Other 19
610 Third 20 AUG 2019 58 Invasive 66
610 Initial 17 Mar 2018 25 Invasive 17
*Example of Output;
Subject Type Date Trade Procedure Total Output
500 Initial 15 AUG 2017 6 Invasive 20 20/20
500 Initial 15 AUG 2017 9 Surface 35 35/35
500 Followup 15 AUG 2018 8 Invasive 54 54/20
428 Followup 15 AUG 2018 56 Outer 29 29/10
765 Seventh 3 AUG 2018 12 Other 13 13/19
500 Followup 3 JUL 2018 23 surface 98 98/35
428 Initial 3 JUL 2017 34 Outer 10 10/10
765 Initial 20 JUL 2019 4 Other 19 19/19
610 Third 20 AUG 2019 58 Invasive 66 66/17
610 Initial 17 Mar 2018 25 Invasive 17 17/17
解决方案
推荐阅读
- dockerfile - Dockerfile 使用 RHEL8 UBI 镜像注册订阅
- amazon-web-services - 如何在 AWS Cloudformation 中使用 !Join 和 !FindInMap 创建名称标签
- rust - 移入闭包的结构从外部借用参考
- ssl-certificate - 带有 Identity Server 和外部登录的托管 Blazor WASM 在生产环境中不起作用
- python - numpy.linalg.tensorsolve 中的向量化
- python - 如何获取字典元素名称作为列表
- excel - 在两列中搜索值并将其与第三列匹配
- jsp - 反射型 XSS:request.getParameter
- python - Keras 自定义损失函数 - 生存分析截尾
- concurrency - 在 Tcl 中防止 proc reenry 的最佳方法是什么?