<?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: Still having problems converting character variables to numeric variables such as education (yea in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Still-having-problems-converting-character-variables-to-numeric/m-p/832766#M35720</link>
    <description>&lt;P&gt;The TYPE of the variable is much more important than the LENGTH or any FORMAT that might or might not be attached to it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you show is not possible:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;edu is listed as a character value, Len = 2 and Format = $2.&lt;/P&gt;
&lt;P&gt;cg_edu is listed as a character value, Len = 12 Format = F12.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For CQ_EDU to be numeric the maximum storage length it could have is 8.&amp;nbsp; That is because SAS stores all numeric variables as 64-bit floating point numbers.&amp;nbsp; You can store them with less than the full 8 bytes (with the corresponding loss of precision in representing the values) but not with more.&amp;nbsp; But if it is character with a length of 12 then you could NOT use the numeric format F12. with that variable.&amp;nbsp; The type of the format has to match the type of the variable (or value) it is being used to format (aka print as text).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the key thing to look for in the output from PROC CONTENTS it the TYPE of the variable.&amp;nbsp; For example here is the output for SASHELP.CLASS.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1662915838658.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75134i660EF49E86CE8525/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1662915838658.png" alt="Tom_0-1662915838658.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As you can see two of the variables are character and the other three are numeric.&amp;nbsp; Notice also that none of them have a FORMAT attached to them.&amp;nbsp; That is because SAS does not need any special instructions to display character strings or numbers.&amp;nbsp; Even the non-integer values of HEIGHT and WEIGHT.&amp;nbsp; For most outputs SAS will default to using the BEST12. format to display numbers.&amp;nbsp; The BEST format tries to find the best way to represent the value (print the value) in the fixed number of characters specified by the width of the format specification.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 11 Sep 2022 17:11:46 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-09-11T17:11:46Z</dc:date>
    <item>
      <title>Still having problems converting character variables to numeric variables such as education (years)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Still-having-problems-converting-character-variables-to-numeric/m-p/832761#M35718</link>
      <description>&lt;P&gt;I'm still confused about changing education (edu) and caregiver education (cg_edu)&amp;nbsp; variable in number of years from character to numeric value. The data set I was given was in SPSS. I imported it as SAS. When I run a proc means on edu, I receive the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Variable edu in list does not match type prescribed for this list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Variable cg_edu in list does not match type prescribed for this list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From watching SAS videos and reading SAS how to and some earlier responses to me in SAS communities, I know there is a way to use an input or put statement. I cannot figure out how to apply this with my data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run a proc contents:&lt;/P&gt;&lt;P&gt;edu is listed as a character value, Len = 2 and Format = $2.&lt;/P&gt;&lt;P&gt;cg_edu is listed as a character value, Len = 12 Format = F12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure what format to put in the INPUT statement for edu and cg_edu.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Sunday;&lt;/P&gt;&lt;P&gt;Set Monday;&lt;/P&gt;&lt;P&gt;edu_numeric = INPUT (edu, format?);&lt;/P&gt;&lt;P&gt;cg_edu_numeric = INPUT (cg_edu, format?);&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 16:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Still-having-problems-converting-character-variables-to-numeric/m-p/832761#M35718</guid>
      <dc:creator>gtucke1</dc:creator>
      <dc:date>2022-09-11T16:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems converting character variables to numeric variables such as education (yea</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Still-having-problems-converting-character-variables-to-numeric/m-p/832762#M35719</link>
      <description>&lt;P&gt;When you get errors in the log, show us the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; log for that data step (or PROC). Do not show us just the errors. Copy and paste the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; log for that data step (or PROC) into the window that appears when you click on the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Insert Log Icon in SAS Communities.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66171iFEC370B1DBF07B28/image-size/large?v=v2&amp;amp;px=999" role="button" title="Insert Log Icon in SAS Communities.png" alt="Insert Log Icon in SAS Communities.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, please show us what PROC CONTENTS says for EDU and CG_EDU, and please show us typical values for these two variables.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 16:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Still-having-problems-converting-character-variables-to-numeric/m-p/832762#M35719</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-11T16:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems converting character variables to numeric variables such as education (yea</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Still-having-problems-converting-character-variables-to-numeric/m-p/832766#M35720</link>
      <description>&lt;P&gt;The TYPE of the variable is much more important than the LENGTH or any FORMAT that might or might not be attached to it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you show is not possible:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;edu is listed as a character value, Len = 2 and Format = $2.&lt;/P&gt;
&lt;P&gt;cg_edu is listed as a character value, Len = 12 Format = F12.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For CQ_EDU to be numeric the maximum storage length it could have is 8.&amp;nbsp; That is because SAS stores all numeric variables as 64-bit floating point numbers.&amp;nbsp; You can store them with less than the full 8 bytes (with the corresponding loss of precision in representing the values) but not with more.&amp;nbsp; But if it is character with a length of 12 then you could NOT use the numeric format F12. with that variable.&amp;nbsp; The type of the format has to match the type of the variable (or value) it is being used to format (aka print as text).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the key thing to look for in the output from PROC CONTENTS it the TYPE of the variable.&amp;nbsp; For example here is the output for SASHELP.CLASS.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1662915838658.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75134i660EF49E86CE8525/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1662915838658.png" alt="Tom_0-1662915838658.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As you can see two of the variables are character and the other three are numeric.&amp;nbsp; Notice also that none of them have a FORMAT attached to them.&amp;nbsp; That is because SAS does not need any special instructions to display character strings or numbers.&amp;nbsp; Even the non-integer values of HEIGHT and WEIGHT.&amp;nbsp; For most outputs SAS will default to using the BEST12. format to display numbers.&amp;nbsp; The BEST format tries to find the best way to represent the value (print the value) in the fixed number of characters specified by the width of the format specification.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 17:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Still-having-problems-converting-character-variables-to-numeric/m-p/832766#M35720</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-11T17:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems converting character variables to numeric variables such as education (yea</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Still-having-problems-converting-character-variables-to-numeric/m-p/832784#M35724</link>
      <description>&lt;P&gt;&lt;STRONG&gt;IF&lt;/STRONG&gt; that F12. was a typo, and the format is in fact &lt;STRONG&gt;$&lt;/STRONG&gt;12., then this will do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;edu_numeric = input(edu,2.);
cg_edu_numeric = input(cg_edu,12.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 11 Sep 2022 21:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Still-having-problems-converting-character-variables-to-numeric/m-p/832784#M35724</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-11T21:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: Still having problems converting character variables to numeric variables such as education (yea</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Still-having-problems-converting-character-variables-to-numeric/m-p/832959#M35739</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 17:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Still-having-problems-converting-character-variables-to-numeric/m-p/832959#M35739</guid>
      <dc:creator>gtucke1</dc:creator>
      <dc:date>2022-09-12T17:45:05Z</dc:date>
    </item>
  </channel>
</rss>

