BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Anita_n
Pyrite | Level 9

Hi all,

if I have a set of id's in table A(a subset of table B) and an tring to create a new dataset from table B. Is it possible to make a reference between the two tables (I want to make a selection depending on the pat_id's in table A)

for a examples using the code below: 

For example if table A conains the following Dataset

pat_id

1

2

3

and table B contains

pat_id  var1   var2

1           35       3.5

2           77        6.7

3          15         5.3

4           11         2.0

5                       1.2

6            54        8.9

proc sql;
create table dataset_new as select var1, var2 from tableB where pat_id in tableA;
quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
maguiremq
SAS Super FREQ

Use a sub-query:

data table_a;
input pat_id;
datalines;
1
2
3
;
run;

data table_b;
input pat_id var1 var2;
datalines;
1 35 3.5
2 77 6.7
3 15 5.3
4 11 2.0
5 . 1.2
6 54 8.9
;
run;

proc sql;
	create table 	want as
		select
					*
		from
					table_b
		where
					pat_id in (
									select 
												pat_id
									from
												table_a		)
		;
quit;
Obs pat_id var1 var2 
1 1 35 3.5 
2 2 77 6.7 
3 3 15 5.3 

More here: http://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p1st65qbmqdks3n1mch4yfcctexi.htm 

View solution in original post

1 REPLY 1
maguiremq
SAS Super FREQ

Use a sub-query:

data table_a;
input pat_id;
datalines;
1
2
3
;
run;

data table_b;
input pat_id var1 var2;
datalines;
1 35 3.5
2 77 6.7
3 15 5.3
4 11 2.0
5 . 1.2
6 54 8.9
;
run;

proc sql;
	create table 	want as
		select
					*
		from
					table_b
		where
					pat_id in (
									select 
												pat_id
									from
												table_a		)
		;
quit;
Obs pat_id var1 var2 
1 1 35 3.5 
2 2 77 6.7 
3 3 15 5.3 

More here: http://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p1st65qbmqdks3n1mch4yfcctexi.htm 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1578 views
  • 0 likes
  • 2 in conversation