<?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: Does Not Start With (multiple options) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Does-Not-Start-With-multiple-options/m-p/863745#M341163</link>
    <description>&lt;P&gt;Just try a few example values and do the comparisons in your head and you will see the problem with your logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the value starts with Unknown the first test if FALSE but the other two are TRUE.&amp;nbsp; Similar result for the other prefixes you are testing for.&amp;nbsp; And if the value is none of them then all three tests are TRUE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You want AND.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or just use the IN operator instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if port=" " and land ^in: ("Unknown" "Other" "Rail") then port=land;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 13 Mar 2023 04:50:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-03-13T04:50:30Z</dc:date>
    <item>
      <title>Does Not Start With (multiple options)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-Not-Start-With-multiple-options/m-p/863708#M341154</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a new character variable in my dataset called port, that is dependent on the values from a different character variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this new port variable, I want the values to equal the land character variable only if the new port variable value is missing, and the values in the land variable &lt;STRONG&gt;does not start&lt;/STRONG&gt; with "Unknown", "Other" , "Rail".&amp;nbsp; I have tried the following code, but it appears to replace the port values with the land values i did not want. I am hoping someone can provide some suggestion to get this code working properly! I have provided an example of my code below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data newloc;&lt;BR /&gt;set othport;&lt;BR /&gt;length port$200;&lt;/P&gt;&lt;P&gt;if port="" and land ^=:"Unknown" or land ^=:"Other" or land ^=:"Rail"&amp;nbsp;&lt;BR /&gt;then port= land;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 02:26:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-Not-Start-With-multiple-options/m-p/863708#M341154</guid>
      <dc:creator>jnivi</dc:creator>
      <dc:date>2023-03-13T02:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Does Not Start With (multiple options)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-Not-Start-With-multiple-options/m-p/863736#M341158</link>
      <description>&lt;P&gt;Your logic needs to use AND in this case&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data newloc;
set othport;
length port$200;

if port="" and land ^=:"Unknown" AND land ^=:"Other" AND land ^=:"Rail" 
then port= land;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 03:17:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-Not-Start-With-multiple-options/m-p/863736#M341158</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-03-13T03:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: Does Not Start With (multiple options)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-Not-Start-With-multiple-options/m-p/863745#M341163</link>
      <description>&lt;P&gt;Just try a few example values and do the comparisons in your head and you will see the problem with your logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the value starts with Unknown the first test if FALSE but the other two are TRUE.&amp;nbsp; Similar result for the other prefixes you are testing for.&amp;nbsp; And if the value is none of them then all three tests are TRUE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You want AND.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or just use the IN operator instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if port=" " and land ^in: ("Unknown" "Other" "Rail") then port=land;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Mar 2023 04:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-Not-Start-With-multiple-options/m-p/863745#M341163</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-13T04:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Does Not Start With (multiple options)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Does-Not-Start-With-multiple-options/m-p/863752#M341167</link>
      <description>&lt;P&gt;I think the problem is with the precedence of operators. AND has higher precedence than OR, just like * has higher precedence than +. So your expression actually evaluates to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(port="" and land ^=:"Unknown") or land ^=:"Other" or land ^=:"Rail" &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will have to use a parathesis to get what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;port="" and (land ^=:"Unknown" or land ^=:"Other" or land ^=:"Rail") &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or use the in: operator, as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 08:40:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Does-Not-Start-With-multiple-options/m-p/863752#M341167</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-03-13T08:40:59Z</dc:date>
    </item>
  </channel>
</rss>

