<?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: Understanding of If Else in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Understanding-of-If-Else/m-p/815208#M321771</link>
    <description>&lt;P&gt;Propcase() doesn't evaluate if a string is propcase or not but it changes a string to propcase. For this reason using the propcase() function in an IF condition is just wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've been actually "surprised" that you even can use propcase() this way ...but then it's a function so why wouldn't SAS allow it even though it's "nonsense".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below test shows you that propcase() always FALSE if used this way so it's no good at all.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  name='ALFRED'; output;
  name='alfred'; output;
  name='Alfred'; output;
run;

data test;
  set have;
  if propcase(name) then bool=1;
  else bool=0;
run;

proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1653567913537.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71790i52A8B0BDA0B7B996/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1653567913537.png" alt="Patrick_0-1653567913537.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you do have a need to test for the casing of a string then let us know and we can provide a correct coding solution.&lt;/P&gt;</description>
    <pubDate>Thu, 26 May 2022 12:28:14 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2022-05-26T12:28:14Z</dc:date>
    <item>
      <title>Understanding of If Else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-of-If-Else/m-p/815188#M321757</link>
      <description>&lt;P&gt;I came across the following line in one of the SAS program which I'm finding hard to understand. Any help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if propcase(name) then name=name2;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 May 2022 10:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-of-If-Else/m-p/815188#M321757</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-05-26T10:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding of If Else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-of-If-Else/m-p/815198#M321763</link>
      <description>&lt;P&gt;Well, that is one of the most bizarre uses of PROPCASE (and bizarre uses of an IF statement) that I have ever seen. If you inherited this code, are there comments about what this line is doing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, the text between IF and THEN&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;propcase(name)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is evaluated as true (a value of 1) or false (a value of 0) ... so a value of 0 is false, and any other non-missing value is true. So this brings up the question, what are some typical values of NAME?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If NAME='George', then propcase('George') is 'George', which is not a number, and so the IF statement is false.&lt;/P&gt;
&lt;P&gt;If NAME='123' then propcase('123') is 123 and so the IF statement is true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want, you can play with this bizarre usage of PROPCASE as follows, so you can see what different values of NAME produce&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
    name='123';
    z=propcase(name);
    if propcase(name) then newvar=1;
    else newvar=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I wouldn't waste any more time on this, as it is really a bad way to write code.&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 11:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-of-If-Else/m-p/815198#M321763</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-26T11:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding of If Else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-of-If-Else/m-p/815199#M321764</link>
      <description>&lt;P&gt;If that's really the exact line of code, it's a mistake.&amp;nbsp; And it should be generating an error (at least a bad NOTE) about invalid data, assuming name has character values that cannot be automatically converted into a numeric value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input name $1. name2 $1.;
  if propcase(name) then name=name2;
  cards ;
Q X
;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1    data have ;
2      input name $1. name2 $1.;
3      if propcase(name) then name=name2;
4      cards ;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      3:6
NOTE: Invalid numeric data, 'Q' , at line 3 column 6.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+--
5          Q X
name=Q name2=  _ERROR_=1 _N_=1
NOTE: The data set WORK.HAVE has 1 observations and 2 variables.

6    ;
7    run ;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 May 2022 11:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-of-If-Else/m-p/815199#M321764</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-26T11:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding of If Else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-of-If-Else/m-p/815208#M321771</link>
      <description>&lt;P&gt;Propcase() doesn't evaluate if a string is propcase or not but it changes a string to propcase. For this reason using the propcase() function in an IF condition is just wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've been actually "surprised" that you even can use propcase() this way ...but then it's a function so why wouldn't SAS allow it even though it's "nonsense".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below test shows you that propcase() always FALSE if used this way so it's no good at all.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  name='ALFRED'; output;
  name='alfred'; output;
  name='Alfred'; output;
run;

data test;
  set have;
  if propcase(name) then bool=1;
  else bool=0;
run;

proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1653567913537.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71790i52A8B0BDA0B7B996/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1653567913537.png" alt="Patrick_0-1653567913537.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you do have a need to test for the casing of a string then let us know and we can provide a correct coding solution.&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 12:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-of-If-Else/m-p/815208#M321771</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-05-26T12:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Understanding of If Else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Understanding-of-If-Else/m-p/815218#M321779</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below test shows you that propcase() always FALSE if used this way so it's no good at all.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The only exception being if the NAME is a numeric code. This would not always return FALSE.&amp;nbsp; But it would still be no good at all.&amp;nbsp; : )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    data have;
2      name='1'; output;
3      name='0'; output;
4      name='5'; output;
5      name='.'; output;
6    run;

NOTE: The data set WORK.HAVE has 4 observations and 1 variables.

7
8    data test;
9      set have;
10     if propcase(name) then bool=1;
11     else bool=0;
12
13     put (name bool)(=) ;
14   run;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      10:6
name=1 bool=1
name=0 bool=0
name=5 bool=1
name=. bool=0
NOTE: There were 4 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.TEST has 4 observations and 2 variables
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 13:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Understanding-of-If-Else/m-p/815218#M321779</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-26T13:09:05Z</dc:date>
    </item>
  </channel>
</rss>

