<?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: multiple set statement for self join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175204#M302065</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;have&lt;/P&gt;&lt;P&gt;id count&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 2&lt;/P&gt;&lt;P&gt;1 3&lt;/P&gt;&lt;P&gt;2 1&lt;/P&gt;&lt;P&gt;2 2&lt;/P&gt;&lt;P&gt;3 1&lt;/P&gt;&lt;P&gt;4 1&lt;/P&gt;&lt;P&gt;5 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;want&lt;/P&gt;&lt;P&gt;id count&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 2&lt;/P&gt;&lt;P&gt;1 3&lt;/P&gt;&lt;P&gt;2 1&lt;/P&gt;&lt;P&gt;2 2&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Jan 2015 18:18:40 GMT</pubDate>
    <dc:creator>Steelers_In_DC</dc:creator>
    <dc:date>2015-01-08T18:18:40Z</dc:date>
    <item>
      <title>multiple set statement for self join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175202#M302063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am misunderstanding using multiple set statements.&amp;nbsp; Here is a piece of code, it's an idea I have but not getting me what I want:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data D3A;&lt;/P&gt;&lt;P&gt;set complete_sort;&lt;/P&gt;&lt;P&gt;by power_id;&lt;/P&gt;&lt;P&gt;count+1;&lt;/P&gt;&lt;P&gt;if first.power_id then count = 1;&lt;/P&gt;&lt;P&gt;where pass_date &amp;lt;&amp;gt; . and '30aug2012'd &amp;lt;= default_date_end &amp;lt;= '01jul2013'd;&lt;/P&gt;&lt;P&gt;if count &amp;gt; 1;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;set complete_sort;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to take count &amp;gt; 1 from one dataset and then join it back to the original dataset and pull all of the records, including where count = 1.&amp;nbsp; Can you show me how to do that in one step with multiple set statements?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank You,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 17:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175202#M302063</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-01-08T17:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: multiple set statement for self join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175203#M302064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure&amp;nbsp; what do you want to do.&lt;/P&gt;&lt;P&gt;Why not provide sample datasets.&lt;/P&gt;&lt;P&gt;You can check &lt;A href="http://www.lexjansen.com/pnwsug/2009/Gehring,%20Renu%20-%20Multiple%20Set%20Statements%20in%20a%20Data%20Step.pdf"&gt;Multiple Set Statements in a Data Step:&lt;/A&gt; for good examples.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 18:10:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175203#M302064</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2015-01-08T18:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: multiple set statement for self join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175204#M302065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;have&lt;/P&gt;&lt;P&gt;id count&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 2&lt;/P&gt;&lt;P&gt;1 3&lt;/P&gt;&lt;P&gt;2 1&lt;/P&gt;&lt;P&gt;2 2&lt;/P&gt;&lt;P&gt;3 1&lt;/P&gt;&lt;P&gt;4 1&lt;/P&gt;&lt;P&gt;5 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;want&lt;/P&gt;&lt;P&gt;id count&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 2&lt;/P&gt;&lt;P&gt;1 3&lt;/P&gt;&lt;P&gt;2 1&lt;/P&gt;&lt;P&gt;2 2&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 18:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175204#M302065</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-01-08T18:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: multiple set statement for self join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175205#M302066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;May be sql can do it more easily.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select * from have&lt;/P&gt;&lt;P&gt;group by id&lt;/P&gt;&lt;P&gt;having count(*)&amp;gt;1&lt;/P&gt;&lt;P&gt;order by id, count;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 18:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175205#M302066</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2015-01-08T18:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: multiple set statement for self join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175206#M302067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For this approach, you do need two SET statements.&amp;nbsp; But the structure will change considerably.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; count=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do until (last.power_id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set complete_sort;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by power_id;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if pass_date &amp;lt;&amp;gt; . and '30aug2012'd &amp;lt;= default_date_end &amp;lt;= '01jul2013'd then count + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do until (last.power_id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set complete_sort;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by power_id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if count &amp;gt; 0 then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The top DO loop processes one POWER_ID, coming up with a COUNT value.&amp;nbsp; Then the bottom DO loop reads the same observations a second time, and outputs (depending on the value of COUNT).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are a couple of basic principles that may help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each SET statement operates 100% independently of any other SET statement.&amp;nbsp; Each reads the first observation, then the second, then the third, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When the DATA step contains an OUTPUT statement, there is no automatic output for every observation.&amp;nbsp; Instead, OUTPUT only takes place where the OUTPUT statement appears.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 18:30:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175206#M302067</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-01-08T18:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: multiple set statement for self join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175207#M302068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know how to do it in sql, I'm trying to get a better understanding of multiple set statements and haven't any good literature for this example online.&lt;/P&gt;&lt;P&gt;Thanks though,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 18:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175207#M302068</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-01-08T18:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: multiple set statement for self join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175208#M302069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Awesome, thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 18:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175208#M302069</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-01-08T18:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: multiple set statement for self join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175209#M302070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I changed the code around a little for the exact result I want, this works great, I appreciate the extra explanation you add.&amp;nbsp; That was a big help:&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do until (last.power_id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set complete_sort;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by power_id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.power_id then count = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do until (last.power_id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set complete_sort;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by power_id;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if count &amp;gt; 1 then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where pass_date &amp;lt;&amp;gt; . and '30aug2012'd &amp;lt;= default_date_end &amp;lt;= '01jul2013'd;*/&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jan 2015 19:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-set-statement-for-self-join/m-p/175209#M302070</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-01-08T19:18:13Z</dc:date>
    </item>
  </channel>
</rss>

