Data merge by merge A PROC SQL equivalent sign whose table record was found in

I concatenate two datasets like this:

data ds3;
  merge ds1(in=in1) ds2(in=in2);
  by mrgvar;
  if in1;
  if in2 then flag=1;
run;

      

If I did it with the PROC SQL step, how can I set the "flag" variable as above?

proc sql;
  create table ds3 as
  select a.*
        ,b.*
        ,???
  from ds1 as a
       left join
       ds2 as b
       on a.mrgvar=b.mrgvar;
quit;

      

+3


source to share


1 answer


A common way is to use a table alias with the join variable.

proc sql;
  create table ds3 as
  select a.*
        ,b.*
        ,case when b.mrgvar is null then 0 else 1 end as flag
  from ds1 as a
       left join
       ds2 as b
       on a.mrgvar=b.mrgvar;
quit;

      



Something about this - if b.mrgvar is null / missing then it only comes from table a. (Yes, you can separately reference the two, even if they are basically the same and concatenated into a results table.)

+3


source







All Articles