<?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: Changing a column from character to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605100#M175526</link>
    <description>&lt;P&gt;How do I do that on a large scale for every value in the field?&lt;/P&gt;</description>
    <pubDate>Mon, 18 Nov 2019 16:48:39 GMT</pubDate>
    <dc:creator>MicheleB0108</dc:creator>
    <dc:date>2019-11-18T16:48:39Z</dc:date>
    <item>
      <title>Changing a column from character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605078#M175512</link>
      <description>&lt;P&gt;I am trying to change a column (MarkDown1) from a character type to numeric type. In a previous post, I asked how to change NA to 0, which I've done successfully. I didn't know if there's a way to change the type that the column is as well. I'm trying to use the numbers in the field for PROC MEANS and then use that to create a line graph.&amp;nbsp; I'm using University Edition Basic 3.8. I attached a picture to show what I'm talking about in case I'm explaining it wrong. Little to no code experience. Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 16:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605078#M175512</guid>
      <dc:creator>MicheleB0108</dc:creator>
      <dc:date>2019-11-18T16:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a column from character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605081#M175515</link>
      <description>&lt;P&gt;See this very small example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    markdown1='439.80';
    num_markdown1=input(markdown1, best8.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Nov 2019 16:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605081#M175515</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-18T16:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a column from character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605100#M175526</link>
      <description>&lt;P&gt;How do I do that on a large scale for every value in the field?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 16:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605100#M175526</guid>
      <dc:creator>MicheleB0108</dc:creator>
      <dc:date>2019-11-18T16:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a column from character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605106#M175531</link>
      <description>&lt;P&gt;Start with a simple step that does one variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
num_markdown1 = input(markdown1, best8.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now, you want to create a dynamic version of that.&lt;/P&gt;
&lt;P&gt;We make a dataset containing variable names:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data varnames;
input name $32.;
datalines;
markdown1
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, we create the first step, using our name list:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set varnames end=done;
if _n_ = 1 then call execute('data want; set have;'):
call execute(cats('num_',name,' = input(',name,', best8.);'));
if done then call execute('run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can create the varnames dataset from dictionary.columns (sashelp.vcolumn), if you can find a suitable where condition to extract the wanted names automatically; otherwise, just expand the step with the datalines.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 17:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605106#M175531</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-18T17:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a column from character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605110#M175534</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299832"&gt;@MicheleB0108&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am trying to change a column (MarkDown1) from a character type to numeric type. In a previous post, I asked how to change NA to 0, which I've done successfully. I didn't know if there's a way to change the type that the column is as well. I'm trying to use the numbers in the field for PROC MEANS and then use that to create a line graph.&amp;nbsp; I'm using University Edition Basic 3.8. I attached a picture to show what I'm talking about in case I'm explaining it wrong. Little to no code experience. Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like you used proc import to read the data.&lt;/P&gt;
&lt;P&gt;You can avoid this particular issue by not using proc import and read data in a data step as needed in the first place. A custom INFORMAT can be a very powerful tool for reading such data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format library = work;
invalue myna (upcase)
'NA' = 0
other = [f16];
run;

data example;
   input x myna.;
datalines;
1
0
na
234.567
NA
0.000045
;&lt;/PRE&gt;
&lt;P&gt;The (UPCASE) option will convert the text encountered to upper case before comparing the value, which may be of use if you have manual data entry and sometimes get "na" "Na" or "nA" actually entered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could such an informat in creating a new variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   numericmarkdown = input(markdown,myna.);
run;&lt;/PRE&gt;
&lt;P&gt;use &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 21:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605110#M175534</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-18T21:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a column from character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605157#M175561</link>
      <description>&lt;P&gt;Thank you so much! One last question, how do you save your current code in the University Edition?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 19:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605157#M175561</guid>
      <dc:creator>MicheleB0108</dc:creator>
      <dc:date>2019-11-18T19:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Changing a column from character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605161#M175564</link>
      <description>&lt;P&gt;Use the Save icon atop the program editor. Save to your folder, so that the code is stored outside the virtual machine.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 19:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-a-column-from-character-to-numeric/m-p/605161#M175564</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-18T19:07:25Z</dc:date>
    </item>
  </channel>
</rss>

