sql - 尽管使用 distinct 在 sas 中获取重复值,但如何删除它们?
问题描述
proc sql;
create table tdstagng.aa as
select distinct * from tdstagng.aa
outer union corr
select distinct * from WORK.DYNAMIC
ORDER by Cdate;`
quit;
输出
此图像是代码的输出,Cdate 是获取当前日期的列。)程序的目标是构建历史数据以标记随时间的变化。
在 2018 年 10 月 15 日的日期,即使整行相同(而不是该日期的 7 行,有 14 行),也有重复的值,我该如何摆脱这个?我用箭头标记了重复的行。
解决方案
您选择了两个不同的集合,然后将它们连接起来,而不是仅仅合并它们。这就是导致重复行的原因。
您是否尝试删除outer
关键字?这是使用 SASHELP.CLASS 数据的示例。
23 proc sql ;
24 create table test1 as
25 select * from sashelp.class where name like 'A%'
26 union corr
27 select * from sashelp.class where sex = 'F'
28 ;
NOTE: Table WORK.TEST1 created, with 10 rows and 5 columns.
29 create table test2 as
30 select * from sashelp.class where name like 'A%'
31 outer union corr
32 select * from sashelp.class where sex = 'F'
33 ;
NOTE: Table WORK.TEST2 created, with 11 rows and 5 columns.
还是做一个子查询?
45
46 create table test3 as
47 select distinct * from
48 (
49 select * from sashelp.class where name like 'A%'
50 outer union corr
51 select * from sashelp.class where sex = 'F'
52 )
53 ;
NOTE: Table WORK.TEST3 created, with 10 rows and 5 columns.
推荐阅读
- python - 从 DataFrame 中选择第 n 个最小值(每一行!)
- android - Android AppCompatEditText,AppCompatTextView, setText 无ID
- c# - WPF StopStoryboard - 动画停止后它不会绑定到 Color 属性
- css - 无法在 reactstrap 卡中设置文本区域的高度
- angular - 添加或删除芯片后如何保持芯片列表自动完成建议打开?
- c++ - 类成员何时使用智能指针或对象
- javascript - 反应生命周期内文档上的反应Keyup事件
- terragrunt - Terragrunt 依赖列表输出作为输入
- python - Python 的范围是半开的(包括开始,不包括停止)
- python - Python 名称错误(未定义“XLMProphetNetTokenizer”)