<?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: When does the OBS= data set option operate? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/When-does-the-OBS-data-set-option-operate/m-p/124742#M25543</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Frank,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Time to RTFM:&amp;nbsp; "Note that with WHERE processing, SAS first subsets the data and then SAS applies OBS= to the subset."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually, it wasn't that obvious in &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000203007.htm" title="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000203007.htm"&gt;SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The "note" was in the example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Doc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Jul 2013 13:05:03 GMT</pubDate>
    <dc:creator>Doc_Duke</dc:creator>
    <dc:date>2013-07-02T13:05:03Z</dc:date>
    <item>
      <title>When does the OBS= data set option operate?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-does-the-OBS-data-set-option-operate/m-p/124741#M25542</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;"&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I have always thought that data set options operate &lt;STRONG&gt;outside&lt;/STRONG&gt; the context of the Proc that uses the data set as input.&lt;/P&gt;&lt;P&gt;That means that the Proc only sees the observations that options like OBS= let through.&lt;/P&gt;&lt;P&gt;I was greatly surprised when I saw the results of the following piece of code (simplified for this purpose).&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;data test ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;do x = 1 to 10 ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; output ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;end ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;run ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;proc sql ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;create table sel1 as&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;select * from test ( obs=1) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;where x &amp;gt; 1 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;I expected that Proc SQL would see only the first observation (with x=1), then decide that it didn't pass the where clause, and thus create a table with 0 observation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-family: arial,helvetica,sans-serif;"&gt;But the result is a single observation with x=2!&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Apparently the obs= and where conditions are combined. But it does not feel right that when I specify that only the first observation should be processed, I get the second observation as output.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Any other views?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jul 2013 12:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-does-the-OBS-data-set-option-operate/m-p/124741#M25542</guid>
      <dc:creator>FrankPoppe</dc:creator>
      <dc:date>2013-07-02T12:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: When does the OBS= data set option operate?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-does-the-OBS-data-set-option-operate/m-p/124742#M25543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Frank,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Time to RTFM:&amp;nbsp; "Note that with WHERE processing, SAS first subsets the data and then SAS applies OBS= to the subset."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually, it wasn't that obvious in &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000203007.htm" title="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000203007.htm"&gt;SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The "note" was in the example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Doc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jul 2013 13:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-does-the-OBS-data-set-option-operate/m-p/124742#M25543</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2013-07-02T13:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: When does the OBS= data set option operate?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-does-the-OBS-data-set-option-operate/m-p/124743#M25544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Frank,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is one of the concepts that I teach in the SAS Programming 2 course. It's also described in the Language Reference:Concepts book, &lt;SPAN style="color: #000000; font-family: '.HelveticaNeueUI'; font-size: 15px; text-align: -webkit-auto;"&gt;&lt;A class="jive-link-external-small" href="http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#n1iok7aawea9zzn1aso4ulosip7l.htm"&gt;http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#n1iok7aawea9zzn1aso4ulosip7l.htm&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Michelle&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jul 2013 13:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-does-the-OBS-data-set-option-operate/m-p/124743#M25544</guid>
      <dc:creator>MichelleHomes</dc:creator>
      <dc:date>2013-07-02T13:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: When does the OBS= data set option operate?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-does-the-OBS-data-set-option-operate/m-p/124744#M25545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Michelle and &lt;A _jive_internal="true" href="https://communities.sas.com/mailto:Doc@Duke/"&gt;Doc@Duke&lt;/A&gt; (both answers are 'correct' but it seems I can only mark one as such).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Btw, I did search for information in the Language Reference, under Data set options, OBS=, and there the remark is still hidden in the examples.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But it still surprises me that the OBS= data set option is executed &lt;STRONG&gt;after&lt;/STRONG&gt; the where clause in Proc SQL. The WHERE statement in a Data Step is a declarative one, and there I see that it has the same 'position' as a data step option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I make a join between two tables with an OBS= option on one of the table the result &lt;EM&gt;is&lt;/EM&gt; what I expected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;
&lt;P&gt;data test ;&lt;BR /&gt;do x = 1 to 10 ;&lt;BR /&gt; output ;&lt;BR /&gt;end ;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;data test2 ;&lt;BR /&gt;do y = 8 , 9 ;&lt;BR /&gt; output ;&lt;BR /&gt;end ;&lt;/P&gt;
&lt;P&gt;proc sql ;&lt;BR /&gt;create table sel1 as&lt;BR /&gt;select * from test ( obs=1)&amp;nbsp; , test2 &lt;BR /&gt;where x = y ;&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;There &lt;EM&gt;is&lt;/EM&gt; an observation in test that will satisfy the where clause, but this query return 0 observation because only the first obs from test is tried.&lt;/P&gt;&lt;P&gt;I haven't found (yet) some paragraph in the documentation explaining when in SQL the OBS= options is executed before the where clause and when after.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jul 2013 13:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-does-the-OBS-data-set-option-operate/m-p/124744#M25545</guid>
      <dc:creator>FrankPoppe</dc:creator>
      <dc:date>2013-07-02T13:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: When does the OBS= data set option operate?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/When-does-the-OBS-data-set-option-operate/m-p/124745#M25546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SAS will attempt to push the WHERE operation down as soon as it can.&amp;nbsp; So your original example with PROC SQL is the same thing that would happen in a data step with a WHERE statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your new example SAS CANNOT push the WHERE clause into the reference to TEST1 because it does not have the variable Y that is used in the WHERE clause.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jul 2013 03:08:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/When-does-the-OBS-data-set-option-operate/m-p/124745#M25546</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-07-03T03:08:27Z</dc:date>
    </item>
  </channel>
</rss>

