<?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: SQL Nested Query in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SQL-Nested-Query/m-p/494642#M72325</link>
    <description>&lt;P&gt;After trimming a few useless bits:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE UNQ_MEMBER AS 
SELECT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
FROM (
    SELECT 
        CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
    FROM MEMBER.MM1718
    UNION 
    SELECT 
        CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
    FROM MEMBER.MM1819 )
GROUP BY CIN
HAVING ENDDTM = MAX(ENDDTM);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 11 Sep 2018 21:17:51 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2018-09-11T21:17:51Z</dc:date>
    <item>
      <title>SQL Nested Query</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-Nested-Query/m-p/494634#M72324</link>
      <description>&lt;P&gt;I haven't ever been a big nested query user, but I'm trying my hand at this one for the sake of brevity in my code. I may have a parenthesis issue, but I've tried a few different ways of adding parenthesis with no luck. Using SAS EG version 7.11.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE UNQ_MEMBER AS SELECT&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM&lt;BR /&gt;FROM (&lt;BR /&gt;SELECT&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM&lt;BR /&gt;FROM MEMBER.MM1718&lt;BR /&gt;UNION&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;SELECT&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM&lt;BR /&gt;FROM MEMBER.MM1819&lt;BR /&gt;ORDER BY CIN, ENDDTM&lt;BR /&gt;) MEMBERSHIP&lt;BR /&gt;GROUP BY CIN&lt;BR /&gt;HAVING ENDDTM = MAX(ENDDTM);&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The following are my separated queries, where I do get the correct results:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;/*PULL AND CONCATENATE MEMBERSHIP FOR RELEVANT DATES*/&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE MEMBERSHIP AS&lt;BR /&gt;SELECT&amp;nbsp;&lt;BR /&gt;DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM&lt;BR /&gt;FROM MEMBER.MM1718&lt;BR /&gt;UNION&amp;nbsp;&lt;BR /&gt;SELECT&amp;nbsp;&lt;BR /&gt;DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM&lt;BR /&gt;FROM MEMBER.MM1819&lt;BR /&gt;ORDER BY CIN, ENDDTM;&lt;BR /&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;/*GIVES TABLE W/ MOST RECENT DATES*/&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE UNQ_MEMBER AS SELECT&amp;nbsp;&lt;BR /&gt;DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM&lt;BR /&gt;FROM MEMBERSHIP&lt;BR /&gt;GROUP BY CIN&lt;BR /&gt;HAVING ENDDTM = MAX(ENDDTM);&lt;BR /&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Sep 2018 20:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-Nested-Query/m-p/494634#M72324</guid>
      <dc:creator>Estelle</dc:creator>
      <dc:date>2018-09-11T20:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Nested Query</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-Nested-Query/m-p/494642#M72325</link>
      <description>&lt;P&gt;After trimming a few useless bits:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE UNQ_MEMBER AS 
SELECT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
FROM (
    SELECT 
        CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
    FROM MEMBER.MM1718
    UNION 
    SELECT 
        CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
    FROM MEMBER.MM1819 )
GROUP BY CIN
HAVING ENDDTM = MAX(ENDDTM);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Sep 2018 21:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-Nested-Query/m-p/494642#M72325</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-11T21:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Nested Query</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SQL-Nested-Query/m-p/494651#M72326</link>
      <description>&lt;P&gt;Yep that's it thanks&lt;/P&gt;</description>
      <pubDate>Tue, 11 Sep 2018 21:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SQL-Nested-Query/m-p/494651#M72326</guid>
      <dc:creator>Estelle</dc:creator>
      <dc:date>2018-09-11T21:44:52Z</dc:date>
    </item>
  </channel>
</rss>

