I want to select all the information from data one based on the data two id.
data one;
input id n;
datalines;
101 a
101 b
101 c
101 d
102 a
102 c
103 f
104 f
105 f
105 u
;
run;
data two;
input id;
datalines;
101
104
105
;
run;
want:
101 a
101 b
101 c
104 f
105 f
105 u
Thanks!
What have you tried already?
Either use a SQL inner join or a data step merge with the IN keyword.
merge A (in=ina) B;
by variable;
if ina;
...
And is the
101 d
missing from your Want data set a typo? If not a type then you will need to describe a rule for identifying that the record should be excluded.
data one;
input id n $;
datalines;
101 a
101 b
101 c
101 d
102 a
102 c
103 f
104 f
105 f
105 u
;
run;
data two;
input id;
datalines;
101
104
105
;
run;
proc sql;
create table want as
select *
from one
where id in (select id from two);
quit;
You have two good solutions suggested: the datastep by @Patrick, and the SQL by @novinosrin. What you should chose depends:
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.