<?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: Conditional execution of where condition in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-execution-of-where-condition-in-proc-sql/m-p/77864#M256420</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Like PG has already pointed out, Proc SQL can't product multiple tables in one pass. However, Hash() can offer a one step approach:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data ds1 ds2 ds3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash ds1(dateset:'tab2(keep=id)');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds1.definekey('id');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds1.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash ds2(dateset:'tab3(keep=id)');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds2.definekey('id');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds2.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash ds3(dateset:'tab4(keep=id)');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds3.definekey('id');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds3.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set tab1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ds1.check() ne 0 then output ds1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if ds1.check()*ds2.check() ne 0 then output ds2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if ds1.check()*ds2.check()*ds3.check() ne 0 then output ds3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not tested, so there maybe typos.&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 17 May 2013 02:50:11 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2013-05-17T02:50:11Z</dc:date>
    <item>
      <title>Conditional execution of where condition in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-execution-of-where-condition-in-proc-sql/m-p/77862#M256418</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif; color: #000000;"&gt;Hello Members,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif; color: #000000;"&gt;Looking for some advice here.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif; color: #000000;"&gt;I have three proc sql statements generating three different tables, based on increasing where condition.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif; color: #000000;"&gt;Example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;STRONG style=": ; font-size: 11pt; background-color: white;"&gt;proc&lt;/STRONG&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; font-size: 11pt; background-color: white;"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;create&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;table&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; ds1 &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;as&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; select&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;&amp;nbsp; a.id, a.dt, &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;a.unit&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; tab1 a&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; where&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; a.id &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;not&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; b.id &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; tab2 b)&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;STRONG style=": ; font-size: 11pt; background-color: white;"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;STRONG style=": ; font-size: 11pt; background-color: white;"&gt;proc&lt;/STRONG&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; font-size: 11pt; background-color: white;"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;create&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;table&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; ds2 &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;as&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; select&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;&amp;nbsp; a.id, a.dt, &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;a.unit&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; tab1 a&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; where&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; a.id &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;not&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; sai_nbr &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; tab2)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; and&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; a.id &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;not&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; sai_nbr &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; tab3)&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;STRONG style=": ; font-size: 11pt; background-color: white;"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;STRONG style=": ; font-size: 11pt; background-color: white;"&gt;proc&lt;/STRONG&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; font-size: 11pt; background-color: white;"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; create&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;table&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; ds3 &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;as&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; select&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;&amp;nbsp; a.id, a.dt,&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; a.unit&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; tab1 a&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; where&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; a.id &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;not&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; sai_nbr &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; tab2)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; and&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; a.id &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;not&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; sai_nbr &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;SPAN style="font-size: 15px; background-color: #ffffff;"&gt;tab&lt;/SPAN&gt;3)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; and&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; a.id &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;not&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; sai_nbr &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt; &lt;SPAN style="font-size: 15px; background-color: #ffffff;"&gt;tab&lt;/SPAN&gt;4)&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, sans-serif;"&gt;&lt;STRONG style=": ; font-size: 11pt; background-color: white;"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-size: 11pt; background-color: white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: arial, helvetica, sans-serif;"&gt;Now, I'd like to create all three data sets in one proc sql or data step. For that, where conditions have to executed conditionally, i.e. when ds1 then one where condition, when ds2 then two where conditions and so on. &lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: arial, helvetica, sans-serif;"&gt;I was thinking of creating a counter, and based on increasing value of the counter from 1 to n, the number of where conditions increase. But I'm not sure how to execute increasing where conditions in consecutive iterations.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: arial, helvetica, sans-serif;"&gt;Compared to data step and proc step, what would be the most efficient and how do I approach the problem? Any advice/idea will be appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: arial, helvetica, sans-serif;"&gt;&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal" style="font-size: 12pt; font-family: 'Times New Roman'; color: #000000;"&gt;&lt;SPAN style="color: #000000; font-size: 11pt; background-color: white; font-family: 'Courier New';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 May 2013 01:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-execution-of-where-condition-in-proc-sql/m-p/77862#M256418</guid>
      <dc:creator>zoomzoom</dc:creator>
      <dc:date>2013-05-17T01:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional execution of where condition in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-execution-of-where-condition-in-proc-sql/m-p/77863#M256419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You cannot create more than one table with a single SQL query. But you might not need more than one table since table ds2 is a subset of table ds1 and table ds3 is a subset of ds2. All three tables could reside togetter as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;create table ds1_2_3 as&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;select&amp;nbsp; &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id, &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dt, &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; unit, &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id not in (select sai_nbr from tab3) as inDs2,&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; calculated inDs2 and id not in (select sai_nbr from tab4) as inDs3&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;from tab1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;where id not in (select sai_nbr from tab2);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Whether this is practical or not depends on the size of the tables and how you intend to use them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 May 2013 02:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-execution-of-where-condition-in-proc-sql/m-p/77863#M256419</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-05-17T02:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional execution of where condition in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-execution-of-where-condition-in-proc-sql/m-p/77864#M256420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Like PG has already pointed out, Proc SQL can't product multiple tables in one pass. However, Hash() can offer a one step approach:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data ds1 ds2 ds3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash ds1(dateset:'tab2(keep=id)');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds1.definekey('id');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds1.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash ds2(dateset:'tab3(keep=id)');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds2.definekey('id');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds2.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; declare hash ds3(dateset:'tab4(keep=id)');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds3.definekey('id');&lt;/P&gt;&lt;P&gt;&amp;nbsp; ds3.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set tab1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ds1.check() ne 0 then output ds1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if ds1.check()*ds2.check() ne 0 then output ds2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if ds1.check()*ds2.check()*ds3.check() ne 0 then output ds3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not tested, so there maybe typos.&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 May 2013 02:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-execution-of-where-condition-in-proc-sql/m-p/77864#M256420</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-05-17T02:50:11Z</dc:date>
    </item>
  </channel>
</rss>

