<?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: Using Arrays to convert character variables to numeric variables? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Using-Arrays-to-convert-character-variables-to-numeric-variables/m-p/726427#M28124</link>
    <description>&lt;P&gt;One question is why are variables that you apparently expect to be numeric actually character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A very common reason for this is using either Proc Import or a wizard that is guessing about the content of your data and the actual data has one or more bits appearing that are causing issues? Does this sound familiar/ likely?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fixing by learning to read data properly can save a lot of time "fixing" things later.&lt;/P&gt;</description>
    <pubDate>Mon, 15 Mar 2021 15:17:56 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-03-15T15:17:56Z</dc:date>
    <item>
      <title>Using Arrays to convert character variables to numeric variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-Arrays-to-convert-character-variables-to-numeric-variables/m-p/726176#M28108</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to try and use an array to change my character variables to numeric variables. Arrays are confusing to me since I am new and much help would be appreciated.&lt;/P&gt;&lt;P&gt;ill give an example of a code I am trying but im not sure if I am even starting correctly?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 12 variables that I want to change from char to numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Array practice[12] $ firstvar-lastvar;
do I=1 to 12;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Mar 2021 02:43:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-Arrays-to-convert-character-variables-to-numeric-variables/m-p/726176#M28108</guid>
      <dc:creator>superman1</dc:creator>
      <dc:date>2021-03-15T02:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using Arrays to convert character variables to numeric variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-Arrays-to-convert-character-variables-to-numeric-variables/m-p/726179#M28109</link>
      <description>&lt;P&gt;Before you can start trying to apply the same operation to multiple variables by using arrays you need to first know what operation you want perform.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot change the type of a variable, so to convert a character variable to a numeric variable you will need to make a new variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newvar = input(oldvar,32.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So in order to convert multiple variables you could just replicate that statement, change the variable names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newvar1 = input(oldvar1,32.);
newvar2 = input(oldvar2,32.);
newvar3 = input(oldvar3,32.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to try instead to use array then you will need two arrays. One for the original character variable and another for the new numeric variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array old oldvar1 oldvar2 oldvar3;
array new newvar1 newvar2 newvar3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can make a DO loop to index through the arrays and make the conversion.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do index=1 to dim(old);
  new[index] = input(old[index],32.);
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Mar 2021 03:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-Arrays-to-convert-character-variables-to-numeric-variables/m-p/726179#M28109</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-15T03:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using Arrays to convert character variables to numeric variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-Arrays-to-convert-character-variables-to-numeric-variables/m-p/726183#M28111</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to change numbers in character variables to numbers in numeric variables, it could be necessary to use the input funcion. Here you have an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.test;
	x1='101,001.23';
	x2='1,001.00';
	x3='1.23';
run;

data work.test2(keep=y);
	set work.test;
	array a[3] $x1-x3;
	do i = 1 to 3;
		y = input(a[i],comma10.2); output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Captura1.PNG" style="width: 428px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55930i04E26C5A04EA1F53/image-size/large?v=v2&amp;amp;px=999" role="button" title="Captura1.PNG" alt="Captura1.PNG" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Captura2.PNG" style="width: 393px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55931i1816A41FA99A0181/image-size/large?v=v2&amp;amp;px=999" role="button" title="Captura2.PNG" alt="Captura2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I hope that this is helpful.&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>Mon, 15 Mar 2021 03:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-Arrays-to-convert-character-variables-to-numeric-variables/m-p/726183#M28111</guid>
      <dc:creator>joseenrique1</dc:creator>
      <dc:date>2021-03-15T03:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using Arrays to convert character variables to numeric variables?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Using-Arrays-to-convert-character-variables-to-numeric-variables/m-p/726427#M28124</link>
      <description>&lt;P&gt;One question is why are variables that you apparently expect to be numeric actually character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A very common reason for this is using either Proc Import or a wizard that is guessing about the content of your data and the actual data has one or more bits appearing that are causing issues? Does this sound familiar/ likely?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fixing by learning to read data properly can save a lot of time "fixing" things later.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 15:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Using-Arrays-to-convert-character-variables-to-numeric-variables/m-p/726427#M28124</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-15T15:17:56Z</dc:date>
    </item>
  </channel>
</rss>

