<?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: IF/THEN/ELSE Statement fulfilling both conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666478#M199418</link>
    <description>&lt;P&gt;One issue is that you created XXTYPE in the first data step and are referencing TYPE in the second data step.&lt;/P&gt;
&lt;P&gt;Another issue is that you are calling the character function STRIP() put giving it a numeric variable as the input.&lt;/P&gt;
&lt;P&gt;Are you trying to convert the numeric variable to character?&amp;nbsp; What format do you want to use to convert the number into text?&lt;/P&gt;
&lt;P&gt;You can use CATS() to automatically convert the numeric value into a string. It will use BEST32 format instead of the BEST12 format.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use VVALUE() function to get the formatted value of the variable.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Jul 2020 20:35:45 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-07-01T20:35:45Z</dc:date>
    <item>
      <title>IF/THEN/ELSE Statement fulfilling both conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666460#M199407</link>
      <description>&lt;P&gt;Hi, I'm sorry to repeat same topic, but i couldn't find in existing "IF-THEN" posted discussions to match my trouble.&lt;BR /&gt;I have can't figure out very simple scenario with "IF-THEN" statement and log issue "Numeric values have been converted to character values":&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input type xxtype $ oldvar;&lt;BR /&gt;cards;&lt;BR /&gt;1 num 0&lt;BR /&gt;1 num 0&lt;BR /&gt;1 num 22&lt;BR /&gt;1 num 5&lt;BR /&gt;1 num 0&lt;BR /&gt;1 num 10&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;/P&gt;&lt;P&gt;length check newvar $200;&lt;BR /&gt;if xxtype="num" then do; check="check1: "||strip(put(type,best12.)); newvar=strip(put(oldvar,best12.)); end;&lt;BR /&gt;else if xxtype="char" then do;&lt;BR /&gt;put "type is character=" type;&lt;BR /&gt;check="check2: "||strip(put(type,best12.));&lt;BR /&gt;newvar=strip(oldvar);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Here is log issue:&lt;BR /&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;/P&gt;&lt;P&gt;ELSE statement should never execute, nevertheless it seem SAS is tripping over the newvar=strip(oldvar); line.&lt;/P&gt;&lt;P&gt;If I missed very obvious logical fault, I apologize for my silly question.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 19:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666460#M199407</guid>
      <dc:creator>Pochemuchka</dc:creator>
      <dc:date>2020-07-01T19:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Statement fulfilling both conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666462#M199409</link>
      <description>&lt;P&gt;That is a one time note of SAS saying that there is an application of a character function to a numeric variable as SAS realises that oldvar is a numeric variable based on input.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 19:47:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666462#M199409</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-07-01T19:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Statement fulfilling both conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666476#M199417</link>
      <description>Thank you Smantha. Is there a better way to populate newvar based on type of oldvar without having SAS log issue?</description>
      <pubDate>Wed, 01 Jul 2020 20:34:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666476#M199417</guid>
      <dc:creator>Pochemuchka</dc:creator>
      <dc:date>2020-07-01T20:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Statement fulfilling both conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666478#M199418</link>
      <description>&lt;P&gt;One issue is that you created XXTYPE in the first data step and are referencing TYPE in the second data step.&lt;/P&gt;
&lt;P&gt;Another issue is that you are calling the character function STRIP() put giving it a numeric variable as the input.&lt;/P&gt;
&lt;P&gt;Are you trying to convert the numeric variable to character?&amp;nbsp; What format do you want to use to convert the number into text?&lt;/P&gt;
&lt;P&gt;You can use CATS() to automatically convert the numeric value into a string. It will use BEST32 format instead of the BEST12 format.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use VVALUE() function to get the formatted value of the variable.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 20:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666478#M199418</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-01T20:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Statement fulfilling both conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666488#M199426</link>
      <description>Hi Tom, thank you for looking into this. I'm trying to macromize "want" datastep: pass oldvar either char or numeric and produce newvar only as character. For example, OldVar=123 =&amp;gt; NewVar='123' or OldVar='free text' =&amp;gt; NewVar='free text'. Thus I created condition if xxtype='char' then just strip OldVar, if xxtype='num' then convert OldVar to character. However, SAS precompiles and outputs false log warning.</description>
      <pubDate>Wed, 01 Jul 2020 21:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666488#M199426</guid>
      <dc:creator>Pochemuchka</dc:creator>
      <dc:date>2020-07-01T21:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Statement fulfilling both conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666499#M199429</link>
      <description>&lt;P&gt;You cannot treat a variable as both numeric and character in the same data step.&amp;nbsp; You might consider using macro code to only generate the right type of statements, but that is not needed if you use either CATS() or VVALUE().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let myvar=oldvar;
data want;
  set have;
  length newvar $200 ;
   newvar=vvalue(&amp;amp;myvar);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;VVALUE() will give you the formatted value and CATS() will give you the raw value.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 22:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666499#M199429</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-01T22:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: IF/THEN/ELSE Statement fulfilling both conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666512#M199439</link>
      <description>Tom, CATS() works beautifully. I will study VVALUE() -- always fun to learn new functions. Thank you so much!</description>
      <pubDate>Thu, 02 Jul 2020 00:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-ELSE-Statement-fulfilling-both-conditions/m-p/666512#M199439</guid>
      <dc:creator>Pochemuchka</dc:creator>
      <dc:date>2020-07-02T00:48:22Z</dc:date>
    </item>
  </channel>
</rss>

