<?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 string to numeric value conversion in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/character-string-to-numeric-value-conversion/m-p/62464#M17765</link>
    <description>Hi:&lt;BR /&gt;
  Consider this example program that uses the PUT function and the INPUT function to convert the SEX variable from SASHELP.CLASS into either a 1 or a 2 -- as a numeric variable. The PUT function creates a character value of either '1' or '2' and then the INPUT function takes that character string and converts it to a number. &lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc format;&lt;BR /&gt;
   value $CONV 'F' = '1'&lt;BR /&gt;
               'M' = '2';&lt;BR /&gt;
run;&lt;BR /&gt;
                               &lt;BR /&gt;
data class;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  newnum = input(put(sex,$conv.),best.);&lt;BR /&gt;
run;&lt;BR /&gt;
                    &lt;BR /&gt;
proc print data=class noobs;&lt;BR /&gt;
  title 'show NEWNUM variable and use SUM statement to prove it is a number';&lt;BR /&gt;
  var name sex newnum;&lt;BR /&gt;
  sum newnum;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Tue, 10 Aug 2010 17:41:02 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2010-08-10T17:41:02Z</dc:date>
    <item>
      <title>character string to numeric value conversion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/character-string-to-numeric-value-conversion/m-p/62463#M17764</link>
      <description>I'm looking for the best method to convert a character string to a numeric value.&lt;BR /&gt;
&lt;BR /&gt;
For example:&lt;BR /&gt;
&lt;BR /&gt;
'EAST' should be converted to the number 1&lt;BR /&gt;
'WEST' should be converted to the number 2&lt;BR /&gt;
'NORTH' should be converted to the number 3&lt;BR /&gt;
'SOUTH' should be converted to the number 4&lt;BR /&gt;
&lt;BR /&gt;
Please let me know if this is not the correct forum.&lt;BR /&gt;
&lt;BR /&gt;
Please let me know if more info is required.&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Tue, 10 Aug 2010 17:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/character-string-to-numeric-value-conversion/m-p/62463#M17764</guid>
      <dc:creator>veblen</dc:creator>
      <dc:date>2010-08-10T17:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: character string to numeric value conversion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/character-string-to-numeric-value-conversion/m-p/62464#M17765</link>
      <description>Hi:&lt;BR /&gt;
  Consider this example program that uses the PUT function and the INPUT function to convert the SEX variable from SASHELP.CLASS into either a 1 or a 2 -- as a numeric variable. The PUT function creates a character value of either '1' or '2' and then the INPUT function takes that character string and converts it to a number. &lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc format;&lt;BR /&gt;
   value $CONV 'F' = '1'&lt;BR /&gt;
               'M' = '2';&lt;BR /&gt;
run;&lt;BR /&gt;
                               &lt;BR /&gt;
data class;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  newnum = input(put(sex,$conv.),best.);&lt;BR /&gt;
run;&lt;BR /&gt;
                    &lt;BR /&gt;
proc print data=class noobs;&lt;BR /&gt;
  title 'show NEWNUM variable and use SUM statement to prove it is a number';&lt;BR /&gt;
  var name sex newnum;&lt;BR /&gt;
  sum newnum;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 10 Aug 2010 17:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/character-string-to-numeric-value-conversion/m-p/62464#M17765</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-10T17:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: character string to numeric value conversion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/character-string-to-numeric-value-conversion/m-p/62465#M17766</link>
      <description>That's a winner.&lt;BR /&gt;
&lt;BR /&gt;
THANKS Cynthia!!!</description>
      <pubDate>Tue, 10 Aug 2010 18:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/character-string-to-numeric-value-conversion/m-p/62465#M17766</guid>
      <dc:creator>veblen</dc:creator>
      <dc:date>2010-08-10T18:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: character string to numeric value conversion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/character-string-to-numeric-value-conversion/m-p/62466#M17767</link>
      <description>An INFORMAT may be a good choice.  As it offers some advantages over a FORMAT with the UPCASE and JUST options and it creats the numeric value directly.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc format;&lt;BR /&gt;
   INvalue news(just upcase) 'EAST'=1 'WEST'=2 'NORTH'=3 'SOUTH'=4;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
data news; &lt;BR /&gt;
   length news $8;&lt;BR /&gt;
   do news='East', 'WEST', ' NORTH', 'SOUTH';&lt;BR /&gt;
      code = input(news,news8.);&lt;BR /&gt;
      output;&lt;BR /&gt;
      end;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
Obs     news     code&lt;BR /&gt;
&lt;BR /&gt;
 1     East        1&lt;BR /&gt;
 2     WEST        2&lt;BR /&gt;
 3      NORTH      3&lt;BR /&gt;
 4     SOUTH       4&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
As in this case where the default W for the user defined INFORAMT is 5, be sure to specify a W that is wide enough to read the entire field.  JUST takes place after the read but before the comparison with INVALUESlist.</description>
      <pubDate>Tue, 10 Aug 2010 19:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/character-string-to-numeric-value-conversion/m-p/62466#M17767</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-08-10T19:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: character string to numeric value conversion</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/character-string-to-numeric-value-conversion/m-p/62467#M17768</link>
      <description>THANKS data_null_;!!!&lt;BR /&gt;
&lt;BR /&gt;
I like this because it creates the numeric value directly.  &lt;BR /&gt;
&lt;BR /&gt;
This is a great forum.</description>
      <pubDate>Wed, 11 Aug 2010 00:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/character-string-to-numeric-value-conversion/m-p/62467#M17768</guid>
      <dc:creator>veblen</dc:creator>
      <dc:date>2010-08-11T00:42:10Z</dc:date>
    </item>
  </channel>
</rss>

