SAS Sql Case语句 - 如何将SAS数据步骤转换为sql案例

时间:2016-01-13 16:09:23

标签: sas case

我正在尝试将SAS数据重写为SAS Sql。到目前为止,我一直在编写版本的语法错误。文档和示例没有说明我正在使用的if / then类型。

以下是原始数据步骤:

data tmp1;
set _tst1;   
if put(tin, $gp.) = 'N' and 
   (missing(npi_num) or index(npi_num,"~") >= 1) then del1=1;    
if put(tin, $gp.) = "Y" or
   put(tin, $msp.) = "Y"  or 
   put(cats(tin, npi_num), $pio.) =: "Y" or 
   put(cats(tin, npi_num), $cpc.) = 'Y' then del2=1;  
if sum(num_elig, msr_yes, num_excl, msr_no) ^gt 0 then del3=1;          
if sum(del1,del2,del3) > 0 then delete;
run;

这是我的尝试:

proc sql;
create table tst as
select *,
case
    when 
       put(tin, $gp.) = 'N' and 
       (missing(npi_num) or index(npi_num,"~") >= 1) 
        then 1
        else 0
        end as del1
    when 
       put(tin, $gp.) = "Y" or
       put(tin, $msp.) = "Y"  or 
       put(cats(tin, npi_num), $pio.) =: "Y" or 
       put(cats(tin, npi_num), $cpc.) = 'Y' 
        then 1
        else 0
        end as del2
    when 
       sum(num_eligible, msr_met, num_exclusion, msr_not_met) ^gt 0
        then 1
        else 0
        end as del3
from _tst1;
quit;

0 个答案:

没有答案