<?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: converting same variable name from char to numeric in the same dataset. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/818079#M322908</link>
    <description>&lt;P&gt;Thank you team&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jun 2022 13:42:50 GMT</pubDate>
    <dc:creator>kajal_30</dc:creator>
    <dc:date>2022-06-14T13:42:50Z</dc:date>
    <item>
      <title>converting same variable name from char to numeric in the same dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/817765#M322790</link>
      <description>&lt;P&gt;I have a dataset 'have' and numeric variables 'a' , 'b' ,'c' , 'd' in it and I want to convert them all into character and assign format $3. keeping the variable names same 'a' , 'b' ,'c' , 'd' .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Kajal&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2022 12:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/817765#M322790</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2022-06-13T12:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: converting same variable name from char to numeric in the same dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/817767#M322791</link>
      <description>&lt;P&gt;Can't be done directly, you cannot change numeric variables to character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could create rename the numeric variables to some other name, then create new character variables with the names you want, assign the values of the numeric variables to the new character variables, then delete the numeric variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Usually it is not a good idea to turn numeric variables into character variables, you are better off leaving them as numeric in most applications. Leaving the variable as numeric is also the easiest approach. So, my advice is to just leave the variables as numeric, instead of making extra work for yourself that has little value.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2022 12:32:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/817767#M322791</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-13T12:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: converting same variable name from char to numeric in the same dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/817777#M322793</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259983"&gt;@kajal_30&lt;/a&gt;&lt;BR /&gt;
&lt;P&gt;I have a dataset 'have' and numeric variables 'a' , 'b' ,'c' , 'd' in it and I want to convert them all into character and assign format $3. keeping the variable names same 'a' , 'b' ,'c' , 'd' .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;Kajal&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is usually no need to attach any FORMAT to a character variable.&amp;nbsp; Are you saying they should be of &lt;STRONG&gt;length&lt;/STRONG&gt; $3 (so they can store strings up to 3 digits long)?&lt;/P&gt;
&lt;P&gt;How do you want the numbers to be converted into strings?&amp;nbsp; Are the values all integers?&amp;nbsp; Are all of the values between -99 and 999?&amp;nbsp; Should values between 0 and 99 use leading zeros?&amp;nbsp; Leading spaces?&amp;nbsp; Or trailing spaces?&lt;/P&gt;
&lt;P&gt;You will have to make NEW variables.&amp;nbsp; You can then DROP the old variables and RENAME to new variables to use the old names.&lt;/P&gt;
&lt;P&gt;Here is code to convert them using the Z3. format so that the small values have leading zeros.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
   array old a b c d ;
   array new $3 x1-x4 ;
   do over old;
      new = put(old,Z3.);
   end;
   drop a b c d ;
   rename x1=a x2=b x3=c x4=d ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you would rather they have leading spaces just use 3. format in the PUT() function.&amp;nbsp; If you want spaces at the end instead of the beginning use the -L suffix to the format specification in the PUT() function.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 14:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/817777#M322793</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-14T14:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: converting same variable name from char to numeric in the same dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/817832#M322820</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have (rename = (a = old_a b=old_b c=old_c));
 
array old(3) old_a old_b old_c;
array new(3) $3. a b c;

do i=1 to dim(old);
new(i) = put(old, $3. -l);
end;

drop old_a old_b old_c;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;untested, the rename data set option may not be exactly correct but this is the idea to do it in one step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2022 16:02:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/817832#M322820</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-13T16:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: converting same variable name from char to numeric in the same dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/817856#M322832</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259983"&gt;@kajal_30&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset 'have' and numeric variables 'a' , 'b' ,'c' , 'd' in it and I want to convert them all into character and assign format $3. keeping the variable names same 'a' , 'b' ,'c' , 'd' .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;Kajal&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maybe what you need is a custom format to make the numeric values appear as character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value cust 0='CAT' 1='DOG' 2='PIG';
run;
data want; 
    set have;
    format a b c d cust.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jun 2022 16:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/817856#M322832</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-13T16:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: converting same variable name from char to numeric in the same dataset.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/818079#M322908</link>
      <description>&lt;P&gt;Thank you team&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 13:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-same-variable-name-from-char-to-numeric-in-the-same/m-p/818079#M322908</guid>
      <dc:creator>kajal_30</dc:creator>
      <dc:date>2022-06-14T13:42:50Z</dc:date>
    </item>
  </channel>
</rss>

