<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: proc sql: making reference to data in another table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-making-reference-to-data-in-another-table/m-p/738623#M230440</link>
    <description>&lt;P&gt;Use a sub-query:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs pat_id var1 var2 
1 1 35 3.5 
2 2 77 6.7 
3 3 15 5.3 
&lt;/PRE&gt;
&lt;P&gt;More here: &lt;A href="http://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p1st65qbmqdks3n1mch4yfcctexi.htm" target="_self"&gt;http://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p1st65qbmqdks3n1mch4yfcctexi.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 03 May 2021 15:47:12 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2021-05-03T15:47:12Z</dc:date>
    <item>
      <title>proc sql: making reference to data in another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-making-reference-to-data-in-another-table/m-p/738621#M230438</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;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)&lt;/P&gt;
&lt;P&gt;for a examples using the code below:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example if table A conains the following Dataset&lt;/P&gt;
&lt;P&gt;pat_id&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;and table B contains&lt;/P&gt;
&lt;P&gt;pat_id&amp;nbsp; var1&amp;nbsp; &amp;nbsp;var2&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;35&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3.5&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;77&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6.7&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5.3&lt;/P&gt;
&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2.0&lt;/P&gt;
&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1.2&lt;/P&gt;
&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 54&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8.9&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table dataset_new as select var1, var2 from tableB where pat_id in tableA;
quit;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 15:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-making-reference-to-data-in-another-table/m-p/738621#M230438</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2021-05-03T15:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql: making reference to data in another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-making-reference-to-data-in-another-table/m-p/738623#M230440</link>
      <description>&lt;P&gt;Use a sub-query:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs pat_id var1 var2 
1 1 35 3.5 
2 2 77 6.7 
3 3 15 5.3 
&lt;/PRE&gt;
&lt;P&gt;More here: &lt;A href="http://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p1st65qbmqdks3n1mch4yfcctexi.htm" target="_self"&gt;http://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p1st65qbmqdks3n1mch4yfcctexi.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 15:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-making-reference-to-data-in-another-table/m-p/738623#M230440</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-05-03T15:47:12Z</dc:date>
    </item>
  </channel>
</rss>

