<?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: Character variable equals.. (different ways of putting it) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/488198#M127238</link>
    <description>&lt;P&gt;A few notes ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;None of these are the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not possible for CLASS to be both "1A" and "1B" on the same observation.&amp;nbsp; Most likely you meant to use OR instead of AND:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if class = "1A" or class = "1B" then newclass="1A";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For that statement, there is an equivalent:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if class in ("1A" "1B") then newclass="1A";&lt;/P&gt;</description>
    <pubDate>Mon, 20 Aug 2018 13:53:44 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-08-20T13:53:44Z</dc:date>
    <item>
      <title>Character variable equals.. (different ways of putting it)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/488197#M127237</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a character variable, class, that can equal the following values; 1A, 1B, 1C and 1D.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would normally write out what the character variable ought to be equal to, like the following code:&lt;/P&gt;&lt;P&gt;data test1; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if &lt;STRONG&gt;class="1A" and class="1B"&lt;/STRONG&gt; then newclass="1A"&lt;/P&gt;&lt;P&gt;drop class; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have sometimes stumbled upon the code below. My question is if the code below equals or will produce the same results as the code above?&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test1; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if &lt;STRONG&gt;class="1A&amp;amp;1B"&lt;/STRONG&gt; then newclass="1A"&lt;/P&gt;&lt;P&gt;drop class; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also stumbled upon this particular code below. Is this the same as the one above?:&lt;/P&gt;&lt;P&gt;data test1; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if &lt;STRONG&gt;class="1A, 1B"&lt;/STRONG&gt; then newclass="1A"&lt;/P&gt;&lt;P&gt;drop class; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 13:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/488197#M127237</guid>
      <dc:creator>Marleneek</dc:creator>
      <dc:date>2018-08-20T13:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: Character variable equals.. (different ways of putting it)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/488198#M127238</link>
      <description>&lt;P&gt;A few notes ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;None of these are the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not possible for CLASS to be both "1A" and "1B" on the same observation.&amp;nbsp; Most likely you meant to use OR instead of AND:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if class = "1A" or class = "1B" then newclass="1A";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For that statement, there is an equivalent:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if class in ("1A" "1B") then newclass="1A";&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 13:53:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/488198#M127238</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-20T13:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Character variable equals.. (different ways of putting it)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/488200#M127239</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1; set test;
  if class="1A" and class="1B" then newclass="1A"
drop class; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can't work. The condition can never be true, as the two parts of the "and" are mutually exclusive. Could only work if used with an "or".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1; set test;
  if class="1A&amp;amp;1B" then newclass="1A"
drop class; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Tests for the literal string "1A&amp;amp;1B". Since 1B can't be a macro variable name, no macro resolution will be done (&amp;amp; is a macro trigger).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1; set test;
  if class="1A, 1B" then newclass="1A"
drop class; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once again, tests for the literal string "1A, 1B" (including the blank).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are you trying to achieve?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 13:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/488200#M127239</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-20T13:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Character variable equals.. (different ways of putting it)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/489196#M127669</link>
      <description>&lt;P&gt;I have to use code from another SAS program not written by me, which is why I am trying to understand what class="1A, 1B" means and how SAS runs&amp;nbsp;this command. When I e.g. run the code below, I don't get&amp;nbsp;any observations in my new dataset "english_a_b", which seems strange. It is always the case when I use if class="1A, 1B" or some variation like '1A, 1B, 1C'. Maybe SAS test for the literal string and does not find a match, which is why I don't get any observations..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data english_a_b; set teacherenglish;
if class ne '1A, 1B" then delete; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Aug 2018 10:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/489196#M127669</guid>
      <dc:creator>Marleneek</dc:creator>
      <dc:date>2018-08-23T10:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Character variable equals.. (different ways of putting it)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/489197#M127670</link>
      <description>&lt;P&gt;Exactly.&amp;nbsp; SAS is looking for a match on the entire string, not a match on pieces within the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Functions might be able to search for pieces, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if findw('1A, 1B', class) then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the IN operator is still safer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if class in ('1A' '1B') then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Someone else wrote the program?&amp;nbsp; It could still be wrong.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 11:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/489197#M127670</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-23T11:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Character variable equals.. (different ways of putting it)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/489198#M127671</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/190706"&gt;@Marleneek&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have to use code from another SAS program not written by me, which is why I am trying to understand what class="1A, 1B" means and how SAS runs&amp;nbsp;this command. When I e.g. run the code below, I don't get&amp;nbsp;any observations in my new dataset "english_a_b", which seems strange. It is always the case when I use if class="1A, 1B" or some variation like '1A, 1B, 1C'. Maybe SAS test for the literal string and does not find a match, which is why I don't get any observations..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data english_a_b; set teacherenglish;
if class ne '1A, 1B" then delete; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This code is very obviously rubbish. Please post code that does more than just be a syntax error.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 11:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/489198#M127671</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-23T11:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: Character variable equals.. (different ways of putting it)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/489204#M127674</link>
      <description>&lt;P&gt;Thank you for your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have just discovered that my data is truncated which solves my problem with understanding the code.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Aug 2018 11:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-variable-equals-different-ways-of-putting-it/m-p/489204#M127674</guid>
      <dc:creator>Marleneek</dc:creator>
      <dc:date>2018-08-23T11:07:50Z</dc:date>
    </item>
  </channel>
</rss>

