-2

我有以下两个数据集,需要第三个数据集作为输出。

ONE                TWO  
----------         ----------
ID FLAG            NUMB  
1  N               2  
2  Y               3  
3  Y               9  
4  N               2  
5  N               3  
9  Y               9  
10 Y

OUTPUT  
------- 
ID FLAG NEW  
1  N    N  
2  Y    Y   
3  Y    Y  
4  N    N  
5  N    N  
9  Y    Y  
10 Y    N  

如果在 TWO.NUMB 中找到 ONE.ID 并且它是 ONE.FLAG = Y 则新变量 NEW = Y 否则 NEW = N

我能够使用 PROC SQL 来做到这一点,如下所示。

proc sql;  
create table output as
(
   select distinct id, flag, case when numb is null then 'N' else 'Y' end as NEW
   from one
   left join
   two
   on id = numb
   and flag = 'Y'
);
quit;

这可以在数据步骤/合并中完成吗?

4

1 回答 1

0

因为你有一个 sql 步骤尝试,所以这是一个改进

--此sql步骤不需要合并--

proc sql noprint;

    create table output as
    select distinct *, case
                            when id in (select distinct numb from two) then "Y"
                            else "N"
                        end as new
    from one
    ;
quit; 
于 2013-07-29T13:40:26.570 回答