<?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 Converting Character to Numeric Variable in an IF/THEN statement in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Converting-Character-to-Numeric-Variable-in-an-IF-THEN-statement/m-p/689382#M24651</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to convert this character variable called PriorWeight to a numeric variable called PriorWeight2. I have a range of weight for 292 observations, and am not sure how to include those within the If/Then statements. The range of weights include numbers from 87 to 319, with the last 4 observations having a ? as their PriorWeight, which is why I included the ELSE PriorWeight2 = .;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Convert PriorWeight to a numeric variable */&lt;BR /&gt;IF PriorWeight = 87 - 319 THEN PriorWeight2 = INPUT(PriorWeight,3.);&lt;BR /&gt;ELSE PriorWeight2 = . ;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also already tried (87:319), '87' - '319'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know what you think!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Oct 2020 00:06:42 GMT</pubDate>
    <dc:creator>ssills24</dc:creator>
    <dc:date>2020-10-07T00:06:42Z</dc:date>
    <item>
      <title>Converting Character to Numeric Variable in an IF/THEN statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-Character-to-Numeric-Variable-in-an-IF-THEN-statement/m-p/689382#M24651</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to convert this character variable called PriorWeight to a numeric variable called PriorWeight2. I have a range of weight for 292 observations, and am not sure how to include those within the If/Then statements. The range of weights include numbers from 87 to 319, with the last 4 observations having a ? as their PriorWeight, which is why I included the ELSE PriorWeight2 = .;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Convert PriorWeight to a numeric variable */&lt;BR /&gt;IF PriorWeight = 87 - 319 THEN PriorWeight2 = INPUT(PriorWeight,3.);&lt;BR /&gt;ELSE PriorWeight2 = . ;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also already tried (87:319), '87' - '319'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know what you think!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 00:06:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-Character-to-Numeric-Variable-in-an-IF-THEN-statement/m-p/689382#M24651</guid>
      <dc:creator>ssills24</dc:creator>
      <dc:date>2020-10-07T00:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Character to Numeric Variable in an IF/THEN statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-Character-to-Numeric-Variable-in-an-IF-THEN-statement/m-p/689385#M24652</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF 87 &amp;lt;= PriorWeight &amp;lt;= 319 THEN PriorWeight2 = INPUT(PriorWeight,3.);
ELSE PriorWeight2 = . ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Oct 2020 00:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-Character-to-Numeric-Variable-in-an-IF-THEN-statement/m-p/689385#M24652</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-10-07T00:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Character to Numeric Variable in an IF/THEN statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-Character-to-Numeric-Variable-in-an-IF-THEN-statement/m-p/689391#M24653</link>
      <description>&lt;P&gt;Naturally, I like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;'s solution, above, but as a practical matter, you could just code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PriorWeight2 = INPUT(PriorWeight,3.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If PriorWeight is not numeric, then PriorWeight2 will also be non-numeric.&amp;nbsp; The problem with the above code is that it will generate messages in the log.&amp;nbsp; A clean log is the best practice, so definitely use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;'s solution, but I think it's good to understand what SAS is going to do if it tries a numeric operation on non-numeric data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 00:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-Character-to-Numeric-Variable-in-an-IF-THEN-statement/m-p/689391#M24653</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-07T00:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Character to Numeric Variable in an IF/THEN statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-Character-to-Numeric-Variable-in-an-IF-THEN-statement/m-p/689669#M24685</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp; - This variation of your solution will avoid log messages and would be the approach I would normally take:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PriorWeight2 = INPUT(PriorWeight,?? 3.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Oct 2020 19:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-Character-to-Numeric-Variable-in-an-IF-THEN-statement/m-p/689669#M24685</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-10-07T19:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Character to Numeric Variable in an IF/THEN statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-Character-to-Numeric-Variable-in-an-IF-THEN-statement/m-p/689672#M24686</link>
      <description>&lt;P&gt;Ah!&amp;nbsp; Excellent.&amp;nbsp; Thank you for that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;.&amp;nbsp; I've used ?? in INPUT &lt;STRONG&gt;statement&lt;/STRONG&gt;s, but I've not tried it in an INPUT &lt;STRONG&gt;function&lt;/STRONG&gt;.&amp;nbsp; That's really nice -- so compact.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 19:11:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-Character-to-Numeric-Variable-in-an-IF-THEN-statement/m-p/689672#M24686</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-07T19:11:04Z</dc:date>
    </item>
  </channel>
</rss>

