PROC SQL在从Oracle数据库中提取时错误地消除了缺失值

时间:2016-03-04 21:07:21

标签: sas missing-data proc-sql

当我不希望它们被删除时,我的所有缺失值都将被删除。我假设SAS和Oracle不是很好玩 - 但我不知道解决方案。如果您能提供有关此错误的任何想法,感谢您。

观察字符字段SEX缺少值:

data test ;
  input name $ sex $ age city $;
  if sex = "NA" then sex=' ';
  if city = "Unk" then city = ' ';
  cards;
Gene  M  62 Saginaw
Cyndi F    45 Unk 
Alice  NA  51 Bay City       
Bob   M   55 Unk
;
proc print data=test; run; 

enter image description here

注意我可以在SEX上进行过滤,但仍然缺少值:

proc sql; 
create table que1 as 
select * from test where sex 
not in ('F','M'); 
quit;
proc sql; select * from que1; quit;

enter image description here

通过libname连接观察Oracle表中的vanilla数据:

proc sql; 
create table test as 
select * from dss.student_registrations
where term_code gt '201500'
  and row_type = 'E'
/*  and final_grade not in ('AU','WU') */
;quit;
proc freq data=test; tables final_grade / missing; run; 

enter image description here

现在我将限制放在final_grade上,所有缺失的值都会消失:

proc sql; 
create table test as 
select * from dss.student_registrations
where term_code gt '201500'
  and row_type = 'E'
  and final_grade not in ('AU','WU')
;quit;
proc freq data=test; tables final_grade / missing; run; 

enter image description here

1 个答案:

答案 0 :(得分:3)

SAS具有二进制逻辑(true / false)。如果SAS中的Final_Grade为空,则Final_Grade NOT IN ('AU','WU')为真。 Oracle具有三元逻辑(真/假/未知)。如果Oracle中的Final_Grade为空,则Final_Grade NOT IN ('AU','WU')将是未知的。

虽然您正在编写SAS代码,但它正在将代码传递给Oracle进行处理。建议你试试:

where term_code gt '201500'
and row_type = 'E'
and (final_grade not in ('AU','WU') or final_grade is Null)

来自RDBMS的SAS程序员的这个和许多其他问题在Mike Rhoads的一篇很好的论文中提到,http://support.sas.com/resources/papers/proceedings09/141-2009.pdf