Hi all, I have 2 tables
tableA
ID var1
1 a
2 b
3 c
tableB
ID var1
1 b
4 c
I want to flag the ID in tableA if the ID is in tableB
want
ID var1 flag
1 a 1
2 b 0
3 c 0
Is there a way to do this with proc sql?
proc sql;
create table as want as
select * from tableA
**not sure what to put here***
quit;
data a;
input ID var1 $;
cards;
1 a
2 b
3 c
;
data b;
input ID var1 $;
cards;
1 b
4 c
;
proc sql;
create table want as
select a.* ,a.id=b.id as flag
from a a left join b b
on a.id=b.id;
quit;
data tablea;
input id var1 $;
cards;
1 a
2 b
3 c
;
run;
data tableb;
input id var1 $;
cards;
1 b
4 c
;
run;
proc sql;
create table want as
select a.*,
case when b.id then 1
else 0
end as flag
from tablea a
left join tableb b
on a.id=b.id;
quit;
data a; input ID var1 $; cards; 1 a 2 b 3 c ; data b; input ID var1 $; cards; 1 b 4 c ; proc sql; create table want as select a.* ,exists(select * from b where id=a.id) as flag from a ; quit;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.