<?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: Converting character age variable to numeric with an invalid value in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Converting-character-age-variable-to-numeric-with-an-invalid/m-p/801241#M33208</link>
    <description>&lt;P&gt;Thanks a lot. It works perfectly&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Mar 2022 06:56:39 GMT</pubDate>
    <dc:creator>Novice_</dc:creator>
    <dc:date>2022-03-10T06:56:39Z</dc:date>
    <item>
      <title>Converting character age variable to numeric with an invalid value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-character-age-variable-to-numeric-with-an-invalid/m-p/801220#M33206</link>
      <description>&lt;P&gt;Hi, I have the data in excel as below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Novice__0-1646888573811.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69308i206EF7A99DF907BC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Novice__0-1646888573811.png" alt="Novice__0-1646888573811.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;when I import it with guessingrows the age variable is converted to character. How do I convert it back to numeric with the value of 70+ becoming just a numeric 70? Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 05:04:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-character-age-variable-to-numeric-with-an-invalid/m-p/801220#M33206</guid>
      <dc:creator>Novice_</dc:creator>
      <dc:date>2022-03-10T05:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character age variable to numeric with an invalid value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-character-age-variable-to-numeric-with-an-invalid/m-p/801225#M33207</link>
      <description>&lt;P&gt;Did you import from a text file format such as CSV or Excel/spreadsheet? &lt;/P&gt;
&lt;P&gt;If the file is spreadsheet, do a SAVE AS to create CSV. Import that. It will still have problems but you can copy the code from the log that proc import generated. Clean up a bit to remove line numbers or such.&lt;/P&gt;
&lt;P&gt;Create a custom informat to read 70+ as 70:&lt;/P&gt;
&lt;PRE&gt;Proc format;
invalue mynum
'70+' = 70
other = [8.]
;
run;&lt;/PRE&gt;
&lt;P&gt;run the format code. In the saved generated data step change the informat to the custom informat such as Mynum. created in proc format. If you haven't used Proc Format much be advised that you &lt;STRONG&gt;cannot&lt;/STRONG&gt; name the format or informat with a name ending in digits.&lt;/P&gt;
&lt;P&gt;This approach may be best in the long run if you are going to read multiple similar data steps as you save the data step code and change the infile to the next file and the data set name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OR something like this (which could use a similar informat with an Input function call) with if then else code to create a different variable with the numeric value:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   if oldvar='70+' then newvar=70;
   else newvar = input(oldvar, 8.);
run;&lt;/PRE&gt;
&lt;P&gt;where oldvar is the name of the variable imported as character and newvar is the name of a new variable that will be 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>Thu, 10 Mar 2022 05:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-character-age-variable-to-numeric-with-an-invalid/m-p/801225#M33207</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-10T05:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Converting character age variable to numeric with an invalid value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-character-age-variable-to-numeric-with-an-invalid/m-p/801241#M33208</link>
      <description>&lt;P&gt;Thanks a lot. It works perfectly&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 06:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-character-age-variable-to-numeric-with-an-invalid/m-p/801241#M33208</guid>
      <dc:creator>Novice_</dc:creator>
      <dc:date>2022-03-10T06:56:39Z</dc:date>
    </item>
  </channel>
</rss>

