【发布时间】:2021-04-12 19:48:06
【问题描述】:
我仅在以下数据集中的记录仅因列类型而异的情况下才尝试查找各种组合。例如:前三行仅因列类型不同而不同
给定数据集
ins_id ins_number type
1234 1234-1234-1 AU
1234 1234-1234-1 HM
1234 1234-1234-1 RE
567 567-567-12 TL
567 567-567-13 TL
9101 9101-1234-1 AU
9101 9101-1234-1 TX
9101 9101-1234-1 CN
8854 8854-1234-1 TX
8854 8854-1234-1 GB
8854 8854-1234-1 RE
8854 8854-1234-2 RX
Expected Output:
combination count
AU,HM,RE 1
AU,TX,CN 1
TX,GB,RE 1
我尝试编写查询,但没有得到所需的输出,请帮助:
proc sql;create table tst as select cp.type,
count(distinct ins_id)
from (select distinct fac_prod_typ from dataset3a) cp cross join
(select distinct ins_number from dataset3a) pes left join
dataset3a
on dataset3a.type = cp.type and
dataset3a.ins_number = pes.ins_number
group by cp.type, pes.ins_number;quit;
【问题讨论】:
-
使用 BY 组处理,这里的数据步骤会容易得多。这是一个选项吗?
-
可以,只要输出正确即可。
-
如果在一个组内的不同类型中存在重复类型,您希望该类型出现多少次? (例如一个有6条记录、3种类型和一些重复的id可以总结为
AU,HM(3),RE(2))