Sql 在sas中获取重复值尽管使用distinct,如何删除它们?

Sql 在sas中获取重复值尽管使用distinct,如何删除它们?,sql,sas,enterprise-guide,Sql,Sas,Enterprise Guide,程序(附加两个表并将其存储在后一个表中): 输出 此图像是代码的输出,Cdate是获取当前日期的列。)程序的目标是构建历史数据以标记随时间的变化 在2018年10月15日,即使整行是相同的(而不是该日期的7行有14行),也会有重复的值,我如何消除这种情况?我已经用箭头标记了重复的行 您选择了两个不同的集合,然后将它们连接起来,而不是仅仅合并它们。这就是导致重复行的原因 您是否尝试删除outer关键字?下面是使用SASHELP.CLASS数据的示例 23 proc sql ; 24 cre

程序(附加两个表并将其存储在后一个表中):

输出

此图像是代码的输出,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.

尝试删除外部和更正。

CDate列中的日期格式是什么? 这可能是由于DD/MM/YYYY HH:MM格式——原始日期值中隐藏了时间


如果是这种情况,您可以使用函数
datepart(CDate)
定义计算列--它只保留日期时间值之外的日期

外部进行追加,如果我删除它不会追加我的表,是的,我尝试了整体上不同的操作,但它给了我错误,我不明白。联合将集合合并在一起。除了保留副本之外,还有什么是外部添加?我这样做了,现在我没有得到副本。当我通过查询生成器附加两个表并随后检查代码时,外部union corr就是代码集。
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.
proc sql;
   create table tdstagng.aa as
   select distinct * from tdstagng.aa
   union
   select distinct * from WORK.DYNAMIC
   ORDER by Cdate;
quit;