2016-11-28 135 views
1

当试图合并的SAS数据集我不断收到以下错误的一些变量:如何避免SAS中的此错误?

列115 OUTER UNION的第一个贡献是不能从第二

相同类型作为其 对应

我已经能够解决这个错误通常通过执行以下操作:

  1. 改变变量的相同的“类型”之一其他。例如,将变量A从数字类型更改为字符类型,以便它与其他数据集中的变量匹配,从而允许合并发生。

  2. 导入我试图合并为CSV文件的数据集,然后在proc导入步骤中添加“猜测行”选项。例如:


proc import datafile='xxxxx' 
    out=fadados 
    dbms=csv replace; 
    getnames=yes; 
    guessingrows=200; 
    run; 

然而,有时尽管导入我的文件,CSV格式,并使用“guessingrows”的我仍然得到上面的错误,有时有这么多,这是很费时并且不可能将所有变量实际转换为相同的“类型”,以便它们在数据集之间匹配。

任何人都可以告诉我如何轻松避免这个错误?人们是否有另一种方法来解决这个问题?我经常得到这个错误,我厌倦了必须转换每一个变量。必须有另一种方式!

******更新***** 下面是一个例子,每个人都在问的:如果没有一个例子是很难测试

proc sql; 
     title 'MED REC COMBINED'; 
     create table combined_bn_hw as 
      select * from bndados 
      outer union corr 
      select * from hwdados; 
    quit; 

And here is the output I get in the log: 

21019 proc sql; 
21020  title 'MED REC COMBINED'; 
21021  create table combined_bn_hw as 
21022  select * from bndados 
21023  outer union corr 
21024  select * from hwdados; 
ERROR: Column 115 from the first contributor of OUTER UNION is not the same type as its 
     counterpart from the second. 
ERROR: Column 120 from the first contributor of OUTER UNION is not the same type as its 
     counterpart from the second. 
ERROR: Column 173 from the first contributor of OUTER UNION is not the same type as its 
     counterpart from the second. 
ERROR: Numeric expression requires a numeric format. 
ERROR: Column 181 from the first contributor of OUTER UNION is not the same type as its 
     counterpart from the second. 
ERROR: Column 185 from the first contributor of OUTER UNION is not the same type as its 
     counterpart from the second. 
ERROR: Column 186 from the first contributor of OUTER UNION is not the same type as its 
     counterpart from the second. 
21025 quit; 
NOTE: The SAS System stopped processing this step because of errors. 
NOTE: PROCEDURE SQL used (Total process time): 
     real time   0.01 seconds 
     cpu time   0.00 seconds 
+0

感谢您的编辑,对不起! – chiccaboomberry

+0

*尝试合并SAS *中的数据集时...此试用版在哪里?我们需要数据和代码来重现问题。 – Parfait

+0

只需使用正常的数据步骤即可附加表格,您应该收到更多有用的错误消息。 '数据combined_bn_hw;设置bndados hwdados;运行;'它不会解决你的问题,但它会告诉你具有类型冲突的变量名称。 – Tom

回答

2

不要使用PROC IMPORT猜测什么类型的你在你的数据有变量。它的决定将取决于文件中的值。只需编写一个数据步骤即可自行读取您的CSV文件。然后你可以控制变量是如何定义的。

PROC IMPORT必须猜测您的ID变量是数字还是字符。由于它是基于文件中的内容做的,它可以为不同的数据集做出不同的决定。一个常见的例子是当一个字符变量完全为空时,PROC IMPORT会认为它应该是一个数字变量。

您可以回想一下PROC IMPORT生成和更新的数据步骤代码,以便为变量使用一致的数据类型。但写你自己并不是很难。您不必像PROC IMPORT生成的程序那样复杂。只需包含INFILE语句,定义变量,包括附加任何必需的INFORMATS(如日期值),然后使用简单的INPUT语句。

data want; 
    infile 'myfile.csv' dsd firstobs=2 truncover; 
    length var1 $20 var2 8 ... varlast 8 ; 
    informat var2 yymmdd10.; 
    format var2 yymmdd10.; 
    input var1 -- varlast; 
run; 
+0

你能详细解释一下吗?我不明白你的意思。萨斯很新鲜。你能举一个例子吗? – chiccaboomberry

+0

只需写入像这样的数据步骤即可读取文件。 '数据要; infile'myfile.csv'dsd firstobs = 2 trunco​​ver;长度var1 $ 20 var2 8 ... varlast 8;输入var1 - varlast;运行;'如果您没有变量名称列表,请从CSV文件的第一行复制它们。如果你真的不知道你的文件是什么,你可以回想一下PROC IMPORT生成的代码并修正它,以便使用正确的类型和长度定义变量。 – Tom