如何在SAS中避免此错误?

时间:2016-11-28 20:40:55

标签: sql sas

尝试在SAS中合并数据集时,我会不断为以下错误获取以下错误:

  

来自OUTER UNION的第一个贡献者的第115列与它的类型不同          第二个对应的

我通常通过执行以下操作来解决此错误:

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

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

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

    然而,有时候尽管将我的文件导入为CSV并使用“猜测者”,我仍然会遇到上述错误,有时会有很多以至于非常耗时并且不可能将所有变量实际转换为相同的“类型” “以便它们在数据集之间匹配。

    有人可以告诉我如何轻松避免此错误吗?还有另一种方式让人们解决这个问题吗?我经常遇到这个错误,以至于我厌倦了必须转换每个变量。必须有另一种方式!

    ****** ***** UPDATE 以下是每个人都要求的例子:

      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
    

2 个答案:

答案 0 :(得分:2)

请勿使用PROC IMPORT来猜测数据中包含的变量类型。它的决定取决于文件中的值。只需编写一个数据步骤即可自行读取CSV文件。然后,您可以控制变量的定义方式。

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

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

public InternetExplorerDriver(
    string internetExplorerDriverServerDirectory,
    InternetExplorerOptions options,
    TimeSpan commandTimeout
)

答案 1 :(得分:0)

没有例子,很难测试。你在PROC APPEND上试过FORCE选项吗?

示例:

proc append base=base data=one force; run;
proc append base=base data=two force; run;
proc append base=base data=e04 force; run;

来源: http://www.sascommunity.org/wiki/PROC_APPEND_Alternatives

相关问题