<?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: Select rows in one table according to values in another table (proc sql) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-in-one-table-according-to-values-in-another-table/m-p/732244#M228180</link>
    <description>&lt;P&gt;Let us look at this part of your code. (I am looking at what you have shown here )&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;select	a.id,
		b.*
from (select id from loans.data_apps) a
	left join
	 (select id, 'apps' as var1, var2, var3, var4
	  from loans.data_apps
	 ) b
	 on a.id = b.id&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I don't think you are achieving anything by this join.&lt;/P&gt;
&lt;P&gt;Basically my understanding is that you want records from loans.data_apps that have their id's present in loans.data_collections.&lt;BR /&gt;With this understanding I would write a code something like this&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select id, 'apps' as var1, var2, var3 ,var4 from load.data_apps a&lt;/P&gt;
&lt;P&gt;where a.id in (select id from loans.data_collections);&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;Their will duplicate id's if loans.data_apps has duplicates.&lt;/P&gt;
&lt;P&gt;In that case use select distinct in place of select.&lt;/P&gt;</description>
    <pubDate>Thu, 08 Apr 2021 15:44:35 GMT</pubDate>
    <dc:creator>Sajid01</dc:creator>
    <dc:date>2021-04-08T15:44:35Z</dc:date>
    <item>
      <title>Select rows in one table according to values in another table (proc sql)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-in-one-table-according-to-values-in-another-table/m-p/732190#M228156</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is my code. Basically I have 2 datasets, and I want to get some variables from one (a, b) but the primary key's values have to be the ones that are in another dataset (c).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset C contains some ID's that have a particular status, so I'm interested in getting the variables in A for those ID's only.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I pasted below gives me duplicated rows on some (not all) ID's. Is there an easy way to fix this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For context, loans.data_apps has 1 row per ID, and data_collections can have multiple rows per ID.&lt;/P&gt;&lt;P&gt;Please if possible keep the proc sql notation, this is part of a larger code made by a colleague.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table outputs_table as
select	a.id,
		b.*
from (select id from loans.data_apps) a
	left join
	 (select id, 'apps' as var1, var2, var3, var4
	  from loans.data_apps
	 ) b
	 on a.id = b.id
	inner join
		loans.data_collections c
	on a.id= c.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 12:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-in-one-table-according-to-values-in-another-table/m-p/732190#M228156</guid>
      <dc:creator>catkat96</dc:creator>
      <dc:date>2021-04-08T12:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: Select rows in one table according to values in another table (proc sql)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-rows-in-one-table-according-to-values-in-another-table/m-p/732244#M228180</link>
      <description>&lt;P&gt;Let us look at this part of your code. (I am looking at what you have shown here )&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;select	a.id,
		b.*
from (select id from loans.data_apps) a
	left join
	 (select id, 'apps' as var1, var2, var3, var4
	  from loans.data_apps
	 ) b
	 on a.id = b.id&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I don't think you are achieving anything by this join.&lt;/P&gt;
&lt;P&gt;Basically my understanding is that you want records from loans.data_apps that have their id's present in loans.data_collections.&lt;BR /&gt;With this understanding I would write a code something like this&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;select id, 'apps' as var1, var2, var3 ,var4 from load.data_apps a&lt;/P&gt;
&lt;P&gt;where a.id in (select id from loans.data_collections);&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;Their will duplicate id's if loans.data_apps has duplicates.&lt;/P&gt;
&lt;P&gt;In that case use select distinct in place of select.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 15:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-rows-in-one-table-according-to-values-in-another-table/m-p/732244#M228180</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-04-08T15:44:35Z</dc:date>
    </item>
  </channel>
</rss>

