【问题标题】:SAS Data Integretation Studio : error if lookup returns multiple valuesSAS 数据集成工作室:如果查找返回多个值则出错
【发布时间】:2013-05-17 10:40:20
【问题描述】:

目前,在我们的 DI 工作室工作中,我们进行了几次查找。当某个记录的其中一个查找返回多个值时,查找将选择其中一个(我认为是第一个)进行选择。我实际上更愿意收到错误,因为对我来说这意味着查找尚未明确定义,我可能需要添加额外的“where”表达式。

有没有这样设置的选项?我暂时找不到。

【问题讨论】:

    标签: sas data-integration


    【解决方案1】:

    如果您对宏感到满意,一种选择可能是...

    %macro get_lookup(&in_where);
        proc sql noprint;
            select
                lookup_value,
                count(lookup_value)
            into
                :l_lookup_result,
                :l_count_results
            from lookup table
            where &in_where;
        quit;
    
    %if l_count_results = 1 %then %do;
        %global g_lookup_result;
        %let g_lookup_result = &l_lookup_result;
    %end;
    %else %do;
        %put ERROR: Lookup did not return expected 1 result.;
        %raise_error; 
    %end;
    
    %mend get_lookup;
    
    %get_lookup(&where_clause);
    

    这有点麻烦,但它会完成工作。除非它返回一个以上的值,否则它会倒下。优雅地。 注意:我假设您在宏变量 &where_clause 中构建了一些与查找相关的 where 子句,然后用于填充宏参数 &in_where。我还假设您定义了一个名为 %raise_error 的宏 - 否则,如果此查找未设置 &g_lookup_result 的值,则任何尝试使用宏变量的后续代码都将失败。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-23
      • 2014-10-21
      • 2016-11-09
      • 2016-01-01
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多