sql - 根据列值在 SAS 中添加条目
问题描述
如果特定主题及其各自测试的“计数”列中没有值 1 的条目,我正在尝试向 SAS 数据集添加一个额外的条目。该条目将添加“测试”列值,以及“值”列的“缺失”和计数的 1。
这是数据:
Subject Test Value Count
001 Test1 Normal 0
001 Test2 Normal 0
001 Test2 High 1
002 Test1 Normal 0
002 Test2 Normal 0
002 Test2 Normal 1
我想创建以下数据集:
Subject Test Value Count
001 Test1 Normal 0
001 Test1 Missing 1
001 Test2 Normal 0
001 Test2 High 1
002 Test1 Normal 0
002 Test1 Missing 1
002 Test2 Normal 0
002 Test2 Normal 1
任何见解将不胜感激。
解决方案
我只会使用union all
:
proc sql;
select subject, test, value, count
from data d
union all
select subject, test, 'Missing', 1
from data d
group by subject, test
having max(count) = 0;
推荐阅读
- arrays - 代码没有得到结果
- reactjs - 是否可以避免使用 create-react-app 捆绑 React 库?
- javascript - 从构造函数将对象添加到数组
- java - 我想以新的意图显示图像,图像位于 drawables 文件夹中,通过单击 ImageView
- vba - VBA设置直方图中的箱数
- php - 如何根据数量和预定义的报价添加增量报价
- java - Java Spring - Thymeleaf 将空对象返回给控制器
- django - 如何使用 Nginx 和 django 提供媒体文件?
- ios - 通过 Cocoapods 分发 Swift 项目时使用“内部”不起作用
- c# - 如何在添加到字典之前检查密钥是否存在