<?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: macro to convert character to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-to-convert-character-to-numeric/m-p/672402#M202084</link>
    <description>&lt;P&gt;SAS has a tool for guessing what format text is using.&amp;nbsp; PROC IMPORT.&lt;/P&gt;
&lt;P&gt;Convert your data to a CSV file and then use PROC IMPORT to read it.&amp;nbsp; Now compare the types between the two versions of the data and decide which one you want to use.&lt;/P&gt;
&lt;P&gt;Just make sure not to use a tool for generating the CSV file that adds quotes around &lt;STRONG&gt;all&lt;/STRONG&gt; character values (whether or not quotes are needed) as PROC IMPORT will assume that means the values should be read a character.&lt;/P&gt;</description>
    <pubDate>Sun, 26 Jul 2020 16:26:49 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-07-26T16:26:49Z</dc:date>
    <item>
      <title>macro to convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-convert-character-to-numeric/m-p/672395#M202078</link>
      <description>&lt;P class="p1"&gt;&lt;STRONG&gt;I have a dataset with a 1000 variables that are in character format. The values could be numbers or text. Does anyone know a macro that detect each field one by one and see if it’s a number converts it to numeric, if not leave it as character? &lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jul 2020 15:07:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-convert-character-to-numeric/m-p/672395#M202078</guid>
      <dc:creator>mmehrd</dc:creator>
      <dc:date>2020-07-26T15:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: macro to convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-convert-character-to-numeric/m-p/672397#M202079</link>
      <description>&lt;P&gt;If possible, you need to examine the process that creates this data set and fix the problem there. If this is a conversion of an Excel file to a SAS data set, you probably can fix the problem by converting the Excel file again with the proper options, or by converting Excel to CSV, in which case then you can force certain columns to be numeric.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jul 2020 15:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-convert-character-to-numeric/m-p/672397#M202079</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-26T15:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: macro to convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-convert-character-to-numeric/m-p/672402#M202084</link>
      <description>&lt;P&gt;SAS has a tool for guessing what format text is using.&amp;nbsp; PROC IMPORT.&lt;/P&gt;
&lt;P&gt;Convert your data to a CSV file and then use PROC IMPORT to read it.&amp;nbsp; Now compare the types between the two versions of the data and decide which one you want to use.&lt;/P&gt;
&lt;P&gt;Just make sure not to use a tool for generating the CSV file that adds quotes around &lt;STRONG&gt;all&lt;/STRONG&gt; character values (whether or not quotes are needed) as PROC IMPORT will assume that means the values should be read a character.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jul 2020 16:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-convert-character-to-numeric/m-p/672402#M202084</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-26T16:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: macro to convert character to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-to-convert-character-to-numeric/m-p/672441#M202115</link>
      <description>&lt;P&gt;Below a way how you could implement what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;suggests.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(drop=_:);
  array var {10} $10;
  do _k=1 to 100;
    do _i=1 to dim(var);
      var[_i]=put(_n_,z9.);
      if ceil(ranuni(1)*1000)&amp;gt;990 then var[_i]=cats('A',var[_i]);
    end;
    output;
  end;
run;

filename extfile temp;
proc export 
  data=have
  file=extfile
  dbms=csv
  replace
  ;
run; 

proc import 
  out=want
  file=extfile
  dbms=csv
  replace
  ;
  guessingrows=max;
run;
filename extfile clear;

title 'Variable Types Before and After';
proc sql;
  select libname, memname, name, type
  from dictionary.columns
  where 
    libname='WORK' and
    memname in ('HAVE','WANT')
  order by memname, varnum
  ;
quit;
title;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Jul 2020 04:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-to-convert-character-to-numeric/m-p/672441#M202115</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-07-27T04:42:09Z</dc:date>
    </item>
  </channel>
</rss>

