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:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.