<?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 WHERE statement asking for positive 1 brings in negative 1, not true for IF statement. Why? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24755#M4228</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Steve, If that is indeed the issue, there is a saving grace.&amp;nbsp; SAS treats not zero as true.&amp;nbsp; Thus you could get around it by specifying the logic as boolean.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format NumberVariable 2.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat NumberVariable 2.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input StringVariable $ NumberVariable;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LOAD -1&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LIGHT -1&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LOAD -1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;DATA work.dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET table;&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHERE StringVariable = 'LOAD' AND NumberVariable;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 06 Oct 2011 15:30:03 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2011-10-06T15:30:03Z</dc:date>
    <item>
      <title>WHERE statement asking for positive 1 brings in negative 1, not true for IF statement. Why?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24750#M4223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;This is roughly the DATA step I am running:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333; font-size: 10pt; font-family: arial,helvetica,sans-serif;"&gt;DATA work.dataset;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333333;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;SET db.table;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: 0.5in;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;&lt;SPAN style="color: #333333;"&gt;WHERE StringVariable&lt;/SPAN&gt; = 'LOAD' AND NumberVariable = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;In db.table, NumberVariable takes the value of either 0 or -1. Running this DATA step, one would think that this would bring in 0 observations since there is no instance where NumberVariable=1. However, It does load all observations into work.dataset where NumberVariable= -1 but not where NumberVariable = 0, so it's as if the WHERE statement only looks at the absolute value of NumberVariable&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;﻿﻿&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;Both Format and Informat of NumberVariable is "2." If I remove both the format and informat (i.e. so that running a PROC CONTENTS of this dataset shows blank spaces under the FORMAT and INFORMAT columns for NumberVariable), it still brings in observations where NumberVariable = -1.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;HOWEVER, when I use an IF statement instead of the WHERE statement, so that it reads:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;DATA work.dataset;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: 0.5in;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;SET db.table;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="text-indent: 0.5in;"&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;IF StringVariable = 'LOAD' AND NumberVariable = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;….then 0 observations are read into work.dataset, as one would think as there are no observations in db.table where NumberVariable =1, only those where it =0 or =-1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;Does anyone know why this is?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Oct 2011 14:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24750#M4223</guid>
      <dc:creator>StevWPPI</dc:creator>
      <dc:date>2011-10-06T14:20:39Z</dc:date>
    </item>
    <item>
      <title>WHERE statement asking for positive 1 brings in negative 1, not true for IF statement. Why?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24751#M4224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you provide a simple example, including a dataset in a data step (like the following) where this occurs?&amp;nbsp; When I run the following I don't get any records.&amp;nbsp; Do you if you run it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input StringVariable $ NumberVariable;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LOAD -1&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LIGHT -1&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LOAD -1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;DATA work.dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET table;&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHERE StringVariable = 'LOAD' AND NumberVariable = 1;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Oct 2011 14:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24751#M4224</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-06T14:32:48Z</dc:date>
    </item>
    <item>
      <title>WHERE statement asking for positive 1 brings in negative 1, not true for IF statement. Why?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24752#M4225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I run your test code, I get the same results, 0 records in work.dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wonder if it has to do with how the data are stored on the database from which I am pulling the data? I believe our IT dept. stores these data on our servers using SQL. I am not terribly experienced with database management, so I don't want to say too much about unfamiliar waters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Going back to my original example, if I PROC PRINT on the dataset in my work folder:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: #333333; font-size: 10pt;"&gt;PROC PRINT DATA= work.dataset;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;&lt;SPAN style="color: #333333;"&gt;WHERE &lt;/SPAN&gt;NumberVariable = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;There were 0 observations read from the data set, according to my Log window.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;However, if I PROC PRINT on the original dataset, db.table:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: #333333; font-size: 10pt;"&gt;PROC PRINT DATA= db.table;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: #333333; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;&lt;SPAN style="color: #333333;"&gt;WHERE &lt;/SPAN&gt;NumberVariable = 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial','sans-serif';"&gt;Then all observations in db.table are read, even though for every observation in the Ouptut window, NumberVariable is -1&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Oct 2011 14:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24752#M4225</guid>
      <dc:creator>StevWPPI</dc:creator>
      <dc:date>2011-10-06T14:52:45Z</dc:date>
    </item>
    <item>
      <title>WHERE statement asking for positive 1 brings in negative 1, not true for IF statement. Why?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24753#M4226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since the data are coming from SQL Server, one possibility is that they are actually boolean values.&amp;nbsp; In SQL Server true is represented as -1, where in SAS it is +1.&amp;nbsp; Are you using an older version of SAS (e.g., ver 8)?&amp;nbsp; I ask because there is a hotfix to correct for an optimizer problem related to that specific issue.&amp;nbsp; It was supposed to be corrected in ver 9.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Oct 2011 15:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24753#M4226</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-06T15:10:14Z</dc:date>
    </item>
    <item>
      <title>WHERE statement asking for positive 1 brings in negative 1, not true for IF statement. Why?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24754#M4227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; This is entirely possible. So far in other SQL server datasets at my company that I have encountered in SAS, binary variables are also either 0 or -1. I'm using SAS 9.2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is SAS reading "WHERE NumberVariable=1" as "bring in observations from the SQL server where NumberVariable is true"? But then when the data are stored in a SAS dataset in my work folder, (in work.dataset), what was "true" is now stored as the number "-1" and SAS treats the variable NumberVariable in work.dataset as a number variable and not a boolean, so that -1 and 0 are disassociated from their orignial "true" and "false" meanings?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Oct 2011 15:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24754#M4227</guid>
      <dc:creator>StevWPPI</dc:creator>
      <dc:date>2011-10-06T15:24:23Z</dc:date>
    </item>
    <item>
      <title>WHERE statement asking for positive 1 brings in negative 1, not true for IF statement. Why?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24755#M4228</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Steve, If that is indeed the issue, there is a saving grace.&amp;nbsp; SAS treats not zero as true.&amp;nbsp; Thus you could get around it by specifying the logic as boolean.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format NumberVariable 2.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat NumberVariable 2.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input StringVariable $ NumberVariable;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LOAD -1&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LIGHT -1&lt;/P&gt;&lt;P&gt;LOAD 0&lt;/P&gt;&lt;P&gt;LOAD -1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;DATA work.dataset;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET table;&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHERE StringVariable = 'LOAD' AND NumberVariable;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Oct 2011 15:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24755#M4228</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-06T15:30:03Z</dc:date>
    </item>
    <item>
      <title>WHERE statement asking for positive 1 brings in negative 1, not true for IF statement. Why?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24756#M4229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Excellent, I imagine that this is the issue, and I will also consult with our DB admins.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for your assistance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Oct 2011 15:37:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/WHERE-statement-asking-for-positive-1-brings-in-negative-1-not/m-p/24756#M4229</guid>
      <dc:creator>StevWPPI</dc:creator>
      <dc:date>2011-10-06T15:37:52Z</dc:date>
    </item>
  </channel>
</rss>

