<?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 change the column type from $12. to a numeric type. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-change-the-column-type-from-12-to-a-numeric-type/m-p/781268#M31748</link>
    <description>&lt;P&gt;You cannot change a character variable to a numeric variable. Not a feature of SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you can do is create a new variable that is the numeric equivalent of the character variable, for example in a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first_dose_administered_num = input(first_dose_administered,8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This has nothing to do with formats, which are irrelevant to this type of conversion.&lt;/P&gt;</description>
    <pubDate>Fri, 19 Nov 2021 14:56:07 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-11-19T14:56:07Z</dc:date>
    <item>
      <title>How to change the column type from $12. to a numeric type.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-change-the-column-type-from-12-to-a-numeric-type/m-p/781266#M31747</link>
      <description>&lt;P&gt;I am reading in data from a excel sheet I cannot edit. SAS reads in the columns as CHAR and in order to do some calculations with them, I need to turn them into numeric. I tried a SQL modify statement,&lt;/P&gt;&lt;PRE&gt;/* Changing the columns from characters to numeric */
proc sql;
   alter table race_sjc_mph_data
      modify first_dose_administered format=comma15.;
quit;&lt;/PRE&gt;&lt;P&gt;but this results in this error.&lt;/P&gt;&lt;PRE&gt;      
 
 151        
 152        /* Changing the columns from characters to numeric */
 153        proc sql;
 154           alter table race_sjc_mph_data
 155              modify first_dose_administered format=comma15.;
 ERROR: Character column first_dose_administered requires a character format specification.
 NOTE: Table WORK.RACE_SJC_MPH_DATA has been modified, with 17 columns.
 156        quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 &lt;/PRE&gt;&lt;P&gt;This is the current output properties of that table&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="heyyou1_0-1637333211819.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/65908i3D8AAD61D443AD3B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="heyyou1_0-1637333211819.png" alt="heyyou1_0-1637333211819.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;From what I see in the data, there is not stray characters that would cause an error in parsing from character to numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks you&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 14:48:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-change-the-column-type-from-12-to-a-numeric-type/m-p/781266#M31747</guid>
      <dc:creator>heyyou1</dc:creator>
      <dc:date>2021-11-19T14:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the column type from $12. to a numeric type.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-change-the-column-type-from-12-to-a-numeric-type/m-p/781268#M31748</link>
      <description>&lt;P&gt;You cannot change a character variable to a numeric variable. Not a feature of SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you can do is create a new variable that is the numeric equivalent of the character variable, for example in a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;first_dose_administered_num = input(first_dose_administered,8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This has nothing to do with formats, which are irrelevant to this type of conversion.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 14:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-change-the-column-type-from-12-to-a-numeric-type/m-p/781268#M31748</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-19T14:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the column type from $12. to a numeric type.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-change-the-column-type-from-12-to-a-numeric-type/m-p/781271#M31749</link>
      <description>&lt;P&gt;You cannot change the TYPE of an existing variable (changing the format attached to a variable just changes how you want the variable displayed).&amp;nbsp; So make a new numeric variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the value in the character variable include commas? Is that why you wanted to display the number with the comma format?&amp;nbsp; Try using the COMMA informat when converting the values.&amp;nbsp; That will ignore the commas and dollar signs in the character string when converting the string into a number.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set race_sjc_mph_data;
  dose1 = input(first_dose_administered,comma32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you would prefer the use the existing name for the numeric variable then use RENAME statement to change the names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set race_sjc_mph_data;
  dose1 = input(first_dose_administered,comma32.);
  rename first_dose_administered=dose1_char dose1=first_dose_administered;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Nov 2021 15:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-change-the-column-type-from-12-to-a-numeric-type/m-p/781271#M31749</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-19T15:41:38Z</dc:date>
    </item>
  </channel>
</rss>

