<?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: How to convert Char to Numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Char-to-Numeric/m-p/322922#M71512</link>
    <description>&lt;P&gt;If your source data is not already standardized then also use the UPCASE option so that the informat is no more case sensitive.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue sex_num (just upcase)
    "MALE"  =1
    "FEMALE"=2
    other=99
    ;
quit;

data sample;
  sex="female";
  sex2=input(sex,sex_num.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;H4 class="xis-argument"&gt;UPCASE&lt;/H4&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;P class="xis-paraSimple"&gt;converts all raw data values to uppercase before they are compared to the possible ranges. If you use UPCASE, then make sure the values or ranges that you specify are in uppercase.&lt;/P&gt;
&lt;P class="xis-paraSimple"&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#p1pmw90bl3jzgdn1w4202kclxtho.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#p1pmw90bl3jzgdn1w4202kclxtho.htm&lt;/A&gt;&lt;/P&gt;
&lt;P class="xis-paraSimple"&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Fri, 06 Jan 2017 09:19:30 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-01-06T09:19:30Z</dc:date>
    <item>
      <title>How to convert Char to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Char-to-Numeric/m-p/322906#M71502</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Given Dataset: All hav Char type, i need to change the date type to numeric with odinal value.&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Gender&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;Married&lt;/TD&gt;&lt;TD&gt;Dependents&lt;/TD&gt;&lt;TD&gt;Education&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Male&lt;/TD&gt;&lt;TD&gt;Yes&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;Graduate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Male&lt;/TD&gt;&lt;TD&gt;Yes&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Graduate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Male&lt;/TD&gt;&lt;TD&gt;Yes&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Graduate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Male&lt;/TD&gt;&lt;TD&gt;Yes&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Graduate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Male&lt;/TD&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;Not Graduate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Male&lt;/TD&gt;&lt;TD&gt;Yes&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;Not Graduate&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Used Proc format &amp;nbsp;to change the format:&lt;BR /&gt;proc format;&lt;BR /&gt;value $G&lt;BR /&gt;'Male'=1 'Female'=0;&lt;BR /&gt;Value $M&lt;BR /&gt;'Yes'=1 'No'=0;&lt;BR /&gt;value $D&lt;BR /&gt;"0"=0 "1"=1 "2"=2 "3+"=3;&lt;BR /&gt;value $E&lt;BR /&gt;"Graduate"=1 "Not Graduate"=0 ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BUT NOW HOW I CAN CHANGE THE TYPE FROM CHAR TO NUMERIC??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 08:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Char-to-Numeric/m-p/322906#M71502</guid>
      <dc:creator>pritam26</dc:creator>
      <dc:date>2017-01-06T08:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert Char to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Char-to-Numeric/m-p/322909#M71504</link>
      <description>&lt;P&gt;Hi.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It actually works if you explicitly define the needed vars as numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use the LENGTH statement for this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data _OUT1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;length GENDERN 8.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;GENDERN=put('Male',$G.);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Off course this will produce a warning, as SAS is implictly doing the type conversion for you.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Another way of doing this, and surely the right way would be to create numeric informats&amp;nbsp;instead of formats.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc format;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;invalue G&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Male'=1 'Female'=0;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;invalue M&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Yes'=1 'No'=0;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;invalue D&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"0"=0 "1"=1 "2"=2 "3+"=3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;invalue E&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"Graduate"=1 "Not Graduate"=0 ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data _OUT2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;GENDERN=input('Male',G.);&lt;BR /&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Hope it helps.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 08:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Char-to-Numeric/m-p/322909#M71504</guid>
      <dc:creator>Daniel-Santos</dc:creator>
      <dc:date>2017-01-06T08:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert Char to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Char-to-Numeric/m-p/322917#M71509</link>
      <description>&lt;P&gt;Not sure why you have to recode your variables this way but to answer your question: Use a numeric INformat as this will allow you to read a string and translate it into a numeric value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue sex_num
    "Male" =1
    "Female"=2
    other=99
   ;
quit;

data sample;
  sex="Female";
  sex2=input(sex,sex_num.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 09:02:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Char-to-Numeric/m-p/322917#M71509</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-06T09:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert Char to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Char-to-Numeric/m-p/322918#M71510</link>
      <description>Need to run regression model. Thanks for the help</description>
      <pubDate>Fri, 06 Jan 2017 09:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Char-to-Numeric/m-p/322918#M71510</guid>
      <dc:creator>pritam26</dc:creator>
      <dc:date>2017-01-06T09:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert Char to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Char-to-Numeric/m-p/322922#M71512</link>
      <description>&lt;P&gt;If your source data is not already standardized then also use the UPCASE option so that the informat is no more case sensitive.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue sex_num (just upcase)
    "MALE"  =1
    "FEMALE"=2
    other=99
    ;
quit;

data sample;
  sex="female";
  sex2=input(sex,sex_num.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;H4 class="xis-argument"&gt;UPCASE&lt;/H4&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;P class="xis-paraSimple"&gt;converts all raw data values to uppercase before they are compared to the possible ranges. If you use UPCASE, then make sure the values or ranges that you specify are in uppercase.&lt;/P&gt;
&lt;P class="xis-paraSimple"&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#p1pmw90bl3jzgdn1w4202kclxtho.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#p1pmw90bl3jzgdn1w4202kclxtho.htm&lt;/A&gt;&lt;/P&gt;
&lt;P class="xis-paraSimple"&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 06 Jan 2017 09:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-Char-to-Numeric/m-p/322922#M71512</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-06T09:19:30Z</dc:date>
    </item>
  </channel>
</rss>

