<?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: Use WHERE statement for multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776618#M247028</link>
    <description>Which is why I tend to use the mnemonic LE and GE for most of these comparisons. Then I don't get the order wrong.</description>
    <pubDate>Tue, 26 Oct 2021 21:06:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-10-26T21:06:05Z</dc:date>
    <item>
      <title>Use WHERE statement for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776565#M247006</link>
      <description>&lt;P&gt;I am trying to create a new dataset from an existing one where I only keep certain coded variables. For example, I only want people who are HIV negative AND have engaged in condomless sex or heroin use or sex work, etc.&lt;/P&gt;&lt;P&gt;Here is what I have so far:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data hivneg;
set olddata;
where HIV1 = 2; run;



data hivneg;
where SexBehav3a&amp;lt;=1 or SexBehav4a&amp;lt;=1 or heroin_use=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why doesn't this work? What is the best way to code this?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776565#M247006</guid>
      <dc:creator>westbestern</dc:creator>
      <dc:date>2021-10-26T18:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Use WHERE statement for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776567#M247007</link>
      <description>&lt;P&gt;I think you're missing the SET statement and also suspect one of those ORs should be an &lt;FONT color="#993366"&gt;AND&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data hivneg;
&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;SET oldData;&lt;/FONT&gt;&lt;/STRONG&gt;
where (SexBehav3a&amp;lt;=1 or SexBehav4a&amp;lt;=1) &lt;STRONG&gt;&lt;FONT color="#993366"&gt;AND&lt;/FONT&gt;&lt;/STRONG&gt; heroin_use=1;
run;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/400922"&gt;@westbestern&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to create a new dataset from an existing one where I only keep certain coded variables. For example, I only want people who are HIV negative AND have engaged in condomless sex or heroin use or sex work, etc.&lt;/P&gt;
&lt;P&gt;Here is what I have so far:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data hivneg;
set olddata;
where HIV1 = 2; run;



data hivneg;
where SexBehav3a&amp;lt;=1 or SexBehav4a&amp;lt;=1 or heroin_use=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why doesn't this work? What is the best way to code this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776567#M247007</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-26T18:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Use WHERE statement for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776569#M247008</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;data hivneg;
set olddata;
where (HIV1=2) AND (SexBehav3a=&amp;lt;1 or SexBehav4a=&amp;lt;1 or SexBehav5a=&amp;lt;1);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried doing this but it does not work. It says there's a syntax error. Are you able to put multiple "or" statements in that line?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776569#M247008</guid>
      <dc:creator>westbestern</dc:creator>
      <dc:date>2021-10-26T18:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: Use WHERE statement for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776572#M247011</link>
      <description>Show the actual error please, it usually has enough information to debug the issue. &lt;BR /&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:24:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776572#M247011</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-26T18:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Use WHERE statement for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776575#M247012</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65062iE95F90AC9D074559/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776575#M247012</guid>
      <dc:creator>westbestern</dc:creator>
      <dc:date>2021-10-26T18:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Use WHERE statement for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776576#M247013</link>
      <description>&lt;P&gt;Yes, multiple ORs are allowed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the code you posted:&lt;/P&gt;
&lt;PRE&gt;where (HIV1=2) AND (SexBehav3a=&amp;lt;1 or SexBehav4a=&amp;lt;1 or SexBehav5a=&amp;lt;1);&lt;/PRE&gt;
&lt;P&gt;You're using =&amp;lt;&amp;nbsp; but you intend &amp;lt;=&lt;/P&gt;
&lt;PRE&gt;where (HIV1=2) AND (SexBehav3a&amp;lt;=1 or SexBehav4a&amp;lt;=1 or SexBehav5a&amp;lt;=1);&lt;/PRE&gt;
&lt;P&gt;If that doesn't work, please post the log, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp; mentioned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that SAS uses binary logic (true/false) rather than trinary (true/false/null), and a missing value sorts as a low value.&amp;nbsp; So&amp;nbsp;SexBehav3a&amp;lt;=1 will be true if SexBehav3a has a missing value.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776576#M247013</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2021-10-26T18:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Use WHERE statement for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776578#M247015</link>
      <description>&lt;P&gt;That was it! Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776578#M247015</guid>
      <dc:creator>westbestern</dc:creator>
      <dc:date>2021-10-26T18:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Use WHERE statement for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776579#M247016</link>
      <description>Interestingly not in your first post though....</description>
      <pubDate>Tue, 26 Oct 2021 18:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776579#M247016</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-26T18:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Use WHERE statement for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776618#M247028</link>
      <description>Which is why I tend to use the mnemonic LE and GE for most of these comparisons. Then I don't get the order wrong.</description>
      <pubDate>Tue, 26 Oct 2021 21:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-WHERE-statement-for-multiple-variables/m-p/776618#M247028</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-26T21:06:05Z</dc:date>
    </item>
  </channel>
</rss>

