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 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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