<?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: How to join table properly to only display result with these criteria? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-join-table-properly-to-only-display-result-with-these/m-p/442368#M282727</link>
    <description>&lt;P&gt;Please post example data in a data step. Use the macro provided in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; to convert your existing datasets to data steps. Never post &lt;EM&gt;pictures&lt;/EM&gt; of data, as we have better things to do than type data off pictures and guessing about lengths and formats on the way.&lt;/P&gt;</description>
    <pubDate>Mon, 05 Mar 2018 14:28:35 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-03-05T14:28:35Z</dc:date>
    <item>
      <title>How to join table properly to only display result with these criteria?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-join-table-properly-to-only-display-result-with-these/m-p/442366#M282726</link>
      <description>&lt;P&gt;Hi Guys, i am stuck with this issue where i cannot get the expected result for many days.&lt;/P&gt;&lt;P&gt;I have two tables, Master Well as A and Well Transaction as B.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table A, Master Well is the master table for all Wells where information such as WELL_RK, WELL_NAME, VALID_TO_DTTM.&lt;/P&gt;&lt;P&gt;Below is the sample data&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WELL Master table.PNG" style="width: 445px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18961i9C1B2B15FEA5151B/image-size/large?v=v2&amp;amp;px=999" role="button" title="WELL Master table.PNG" alt="WELL Master table.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table B, Well Transaction where it has data such as WELL_RK, CHANGE_DATE_TIME and etc.&lt;/P&gt;&lt;P&gt;TAKE NOTE A: No WELL_NAME in table B.&lt;/P&gt;&lt;P&gt;TAKE NOTE B: CHOKE_CHANGE_DATE_TIME is also one of the key.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WELL Trans.PNG" style="width: 327px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18962i50B58B0C72A60278/image-size/large?v=v2&amp;amp;px=999" role="button" title="WELL Trans.PNG" alt="WELL Trans.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Recently, the Master Well Table A is loaded with new data where all existing WELL's VALID_TO_DTTM set as 2018-Feb-28, which indicates expired. A new set of WELL are loaded, so the VALID_TO_DTTM are 5999-01-01.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The old expired WELL_RK range from 1 to 2500 while new WELL_RK range from 2501 to 5000.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When WELL Transaction table B joined with Master Well table A to get WELL_RK, the Table B get duplicate records.&lt;/P&gt;&lt;P&gt;Right now, WELL Transaction table B will have mostly but not all duplicate records. Imagine WELL_RK 1 and WELL_RK 2501 belongs to the same WELL_NAME in Master Table A but WELL_RK is expired in Master table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have come out with my own SQL script to try to only display the results in below possible outcome:&lt;BR /&gt;1) If WELL has expired and new records in both tables, only display expired records(For delete later).&lt;/P&gt;&lt;P&gt;2) If WELL only has expired records without new records in table B, no need to display(Nothing to delete later).&lt;/P&gt;&lt;PRE&gt;proc sql;
create table SASA as
select count(*),WELL_NAME,A.CHOKE_CHANGE_DATE_TIME,* from (   
	select
	      WELL_TRANS.*
		  , WELL.*
	   from
	      ODMSCDS.WELL_TRANS as WELL_TRANS left join 
	      ODMSCDS.WELL as WELL on WELL_TRANS.WELL_RK=WELL.WELL_RK
		  
		  
	     )a

group by A.WELL_NAME, A.CHOKE_CHANGE_DATE_TIME
HAVING COUNT (*) &amp;gt;1
ORDER BY A.WELL_NAME ASC, A.WELL_RK DESC, A.CHOKE_CHANGE_DATE_TIME
   ;
quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, it will never give me the result set that i want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i NEED help on improving my SQL statement to print out results that i plan to delete in the next stage which are expired and duplicate records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in Advanced.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 14:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-join-table-properly-to-only-display-result-with-these/m-p/442366#M282726</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2018-03-05T14:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to join table properly to only display result with these criteria?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-join-table-properly-to-only-display-result-with-these/m-p/442368#M282727</link>
      <description>&lt;P&gt;Please post example data in a data step. Use the macro provided in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; to convert your existing datasets to data steps. Never post &lt;EM&gt;pictures&lt;/EM&gt; of data, as we have better things to do than type data off pictures and guessing about lengths and formats on the way.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 14:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-join-table-properly-to-only-display-result-with-these/m-p/442368#M282727</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-05T14:28:35Z</dc:date>
    </item>
  </channel>
</rss>

