<?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 convert character to numeric (varying +/- and decimal) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391173#M93917</link>
    <description>&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to import a tab delimited file into sas. there are a&amp;nbsp;variable containing percentage values, like 6.9873% or -12.0945%. SAS recognizes this&amp;nbsp;variable as character when I import the file. I need this variable to be numeric, so I did the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;newvar=input(oldvar,percent2.6);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However when I look at the data, the code doesn't convert the format consistently, for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;oldvar &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; newvar&lt;/P&gt;&lt;P&gt;12.6545% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12.6545&lt;/P&gt;&lt;P&gt;9.5451% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.095451&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any and all suggestions.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Aug 2017 03:18:20 GMT</pubDate>
    <dc:creator>DavyJones</dc:creator>
    <dc:date>2017-08-28T03:18:20Z</dc:date>
    <item>
      <title>convert character to numeric (varying +/- and decimal)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391173#M93917</link>
      <description>&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to import a tab delimited file into sas. there are a&amp;nbsp;variable containing percentage values, like 6.9873% or -12.0945%. SAS recognizes this&amp;nbsp;variable as character when I import the file. I need this variable to be numeric, so I did the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;newvar=input(oldvar,percent2.6);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However when I look at the data, the code doesn't convert the format consistently, for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;oldvar &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; newvar&lt;/P&gt;&lt;P&gt;12.6545% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12.6545&lt;/P&gt;&lt;P&gt;9.5451% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.095451&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any and all suggestions.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2017 03:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391173#M93917</guid>
      <dc:creator>DavyJones</dc:creator>
      <dc:date>2017-08-28T03:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric (varying +/- and decimal)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391175#M93918</link>
      <description>&lt;P&gt;Use newvar=input(oldvar, percent20.);&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2017 03:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391175#M93918</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-08-28T03:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric (varying +/- and decimal)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391255#M93943</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/161202"&gt;@DavyJones&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to import a tab delimited file into sas. there are a&amp;nbsp;variable containing percentage values, like 6.9873% or -12.0945%. SAS recognizes this&amp;nbsp;variable as character when I import the file. I need this variable to be numeric, so I did the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar=input(oldvar,percent2.6);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However when I look at the data, the code doesn't convert the format consistently, for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;oldvar &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; newvar&lt;/P&gt;
&lt;P&gt;12.6545% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12.6545&lt;/P&gt;
&lt;P&gt;9.5451% &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.095451&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate any and all suggestions.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A brief discussion why you get apparently inconsistent results. When&amp;nbsp;an informat is used with decimals as you have then the first digits(preceding the decimal are the overall length of the expected value and with percent you add 2 to account for potenial leading negative sign and the trailing percent sign. Then&amp;nbsp;the digits after the decimal indicate the number digits that should follow the decimal in the input data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure that you posted the actual code you were running as I get notably different results.&lt;/P&gt;
&lt;PRE&gt;data example;
   x='9.5451%';
   y='12.6545%';
   numx = input(x,percent2.6);
   put numx= best16. ;
   numx2 = input (x,percent9.6);
   put numx2= best16.;
   numy = input(y,percent2.6);
   put numy= best16.;
   numy2 = input (y,percent9.6);
   put numy2= best16.;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Aug 2017 15:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391255#M93943</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-28T15:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric (varying +/- and decimal)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391280#M93957</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I think OP had a wider character variable that put the percent sign outside of the informat reach.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2017 17:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391280#M93957</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-08-28T17:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric (varying +/- and decimal)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391287#M93962</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I think OP had a wider character variable that put the percent sign outside of the informat reach.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I agree that OP was missing something. I wasn't going to guess too much away from what was shown though and use of any format with 2.6 needed some comment.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2017 17:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391287#M93962</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-28T17:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: convert character to numeric (varying +/- and decimal)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391702#M94144</link>
      <description>&lt;P&gt;Thanks for your comments. Yes, you are right. The source of the problem was not converting the percent numbers from character to numeric, but it was importing the data into SAS. Apparantly, as I didn't determine the length of the variable properly, the percentage sign has been removed for some values while kept for the others.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 00:04:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-to-numeric-varying-and-decimal/m-p/391702#M94144</guid>
      <dc:creator>DavyJones</dc:creator>
      <dc:date>2017-08-30T00:04:45Z</dc:date>
    </item>
  </channel>
</rss>

