sas - 如何将 SAS 中的 x 变量与 proc freq 分组?-- 在 SAS proc 中使用交叉表对类别进行分组
问题描述
我会很感激你在这方面的帮助......
我有两列,我想获取类型是 1 还是 2 的月数,所以我使用了 proc freq:
proc freq DATA= count_types;
output out= counts;
TABLE amount_of_months * Type / nocum nopercent norows;
proc freq 返回如下结果:
Months | Type |Grant Total
-----------------+-----------------+----------------+-----------
1 |count(type1)=41 | count(type2)=60| 101
2 |count(type1)=50 | count(type2)=20| 70
3 |count(type1)=60 | count(type2)=30| 90
4 |count(type1)=10 | count(type2)=40| 50
5 |count(type1)=45 | count(type2)=15| 60
...
输出表如下所示:
amount_of_months | Type (contains type1=t1 or type2=t2) |
------------------------------------------------------------------------------
1 | t1 | 41 =count(type1)
1 | t2 | 60 =count(type 2)
2 | t1 | 50 =count(type 1)
2 | t2 | 20 =count(type 2)
3 | t1 | 60 =count(type 1)
3 | t2 | 30 =count(type 2)
4 | t1 | 10 =count(type 1)
4 | t2 | 40 =count(type 2)
5 | t1 | 45 =count(type 1)
5 | t2 | 15 =count(type 2)
我想得到一个如下所示的 proc freq...而不是 1、2、3、4、5:
所以我可以得到这样的组:
Months| Type
---------------------+-------------------
<2 | count(type1) | count(type2)
2-4 | count(type1) | count(type2)
4>+ | count(type1) | count(type2)
---------------------+-------------------
是否可以直接使用 proc freq 或者我应该在两个不同的列中创建一个包含 2 种类型的表?
我尝试使用 proc 格式,但在 case 但它不起作用...这个问题来自 Type 列吗?
代码尝试
proc format;
value amount_of_months
0-2 = '<2'
2-4 = '2-4'
4-high = '4+'
;
proc freq data = count_types;
tables amount_of_months * type / norow nocol nopct ;
format amount_of_months amount_of_months. ;
run;
解决方案
推荐阅读
- javascript - express 4.x json空对象
- node.js - 在多部分文件上传后从 node.js 流式传输存档流
- ios - Realm Swift 更改命名变量的数据类型
- image - 谷歌播放控制台的图像和图标调整大小
- r - 使用 R Markdown 进行 Beamer 演示
- php - 数据库行轮询服务
- react-native - React Native Navigation Drawer - 打开不在抽屉中的页面
- rust - 将非平凡的 gstreamer“pad 回调”作为盒装闭包返回
- flutter - 如何在 Flutter 中移除 ListView 高亮颜色?
- html - 以未损坏的边界半径滚动