<?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: convert all numeric variables to charater at once in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/315018#M61607</link>
    <description>&lt;P&gt;Here's an alternative:&amp;nbsp; run two proc transposes, one for numerics (naming vars NUM1-NUMn)&amp;nbsp; and one for character (naming vars CHAR1-CHARn), where n is the number of observations in the source data set.&amp;nbsp;&amp;nbsp;Each of the result files will get the same number of variables (n,&amp;nbsp; excluding the new variable _NAME_).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then just SET them both, and convert NUM1-NUMn to character form in CHAR1-CHARn.&amp;nbsp; Drop the NUM: vars. &amp;nbsp;No need to determine how many variables of character vs numeric there are:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sashelp.class out=tn  prefix=num;
run;

proc transpose data=sashelp.class  out=tc  prefix=char;
  var _character_;
run;

data want;
  set tn (in=in_n) tc;
  array n {*} num: ;
  array c {*} char: ;
  if in_n then do I=1 to dim(n);
    c{I}=put(n{I},8.);
  end;
  drop num: I ;
run;  
  

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Nov 2016 00:38:14 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2016-11-29T00:38:14Z</dc:date>
    <item>
      <title>convert all numeric variables to charater at once</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/314934#M61595</link>
      <description>&lt;TABLE width="256" style="width: 192pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="64" style="width: 48pt;" span="4" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD width="64" height="20" style="border: 0.5pt solid windowtext; border-image: none; width: 48pt; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;CA&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border-width: 0.5pt 0.5pt 0.5pt 0px; border-style: solid solid solid none; border-color: windowtext windowtext windowtext black; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Item&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border-width: 0.5pt 0.5pt 0.5pt 0px; border-style: solid solid solid none; border-color: windowtext windowtext windowtext black; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;CA1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="64" style="border-width: 0.5pt 0.5pt 0.5pt 0px; border-style: solid solid solid none; border-color: windowtext windowtext windowtext black; width: 48pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;SAL&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: black windowtext windowtext; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;12356&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;NO&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;856&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;YES&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: black windowtext windowtext; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;34527&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;YES&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;245&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2.56&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15pt;"&gt;
&lt;TD height="20" align="right" style="border-width: 0px 0.5pt 0.5pt; border-style: none solid solid; border-color: black windowtext windowtext; height: 15pt; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;56789&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;123&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD align="right" style="border-width: 0px 0.5pt 0.5pt 0px; border-style: none solid solid none; border-color: black windowtext windowtext black; background-color: transparent;"&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3.2&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hI ,&lt;/P&gt;
&lt;P&gt;i Have a dataset like above and i am trying to transpose the dataset but i have colums which are only numeric and other columns which are alphanumeric so how can i convert all variables (i have hundreds of variables ) to character at once so that i can use sigle proc transpose for the dataset&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone pls help Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2016 20:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/314934#M61595</guid>
      <dc:creator>chennupriya</dc:creator>
      <dc:date>2016-11-28T20:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: convert all numeric variables to charater at once</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/314939#M61597</link>
      <description>&lt;P&gt;What are you looking to get as output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember a column in SAS can hold only one type of variable, a character or a numeric variable.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2016 20:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/314939#M61597</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-28T20:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: convert all numeric variables to charater at once</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/314941#M61598</link>
      <description>&lt;P&gt;I am looking to have CA and CA1 also to be character but i have 100's of columns in my dataset so how can i chnage all columns into character&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2016 20:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/314941#M61598</guid>
      <dc:creator>chennupriya</dc:creator>
      <dc:date>2016-11-28T20:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: convert all numeric variables to charater at once</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/314944#M61599</link>
      <description>&lt;P&gt;You can reference all numeric columns using _numeric_, but you need to know how many because you need to create new variables to hold the character values. &amp;nbsp;If you're transposing, it maybe better to transpose and convert at once.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	array nums(*) _numeric_;
	array chars(*) _character_;

	do i=1 to dim(nums);
		variable_name=vname(nums(i));
		value = put(nums(i), 8.);
		output;
	end;

	do i=1 to dim(chars);
		variable_name=vname(nums(i));
		value = chars(i);
		output;
	end;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2016 20:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/314944#M61599</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-28T20:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: convert all numeric variables to charater at once</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/314949#M61600</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Convert all numeric variables to character at once

Can also do using datastep _numeric_  array but may need to rename
R can also do this for you

https://goo.gl/zpYfS4
https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/314934


HAVE
===

Up to 40 obs WORK.HAVE total obs=3

Obs      CA     ITEM    CA1    SAL

 1     12356    NO      856    YES
 2     34527    YES     245    2.56
 3     56789    1       123    3.2


 -- CHARACTER --
ITEM           C    8       NO
SAL            C    8       YES
TOTOBS         C    16      3


 -- NUMERIC --
CA             N    8       12356
CA1            N    8       856

WANT  ( I did not convert CA because it looks like a key?)
===========================================================

Up to 40 obs WORK.HAVXPOXPO total obs=3

Obs      CA     ITEM    CA1    SAL

 1     12356    NO      856    YES
 2     34527    YES     245    2.56
 3     56789    1       123    3.2


 Variables in Creation Order

#    Variable    Type    Len

1    CA          Num       8
2    ITEM        Char     12
3    CA1         Char     12
4    SAL         Char     12


WORKING CODE
============

    proc transpose data=have out=havxpo;
    by ca;
    var _all_;
    run;quit;

FULL SOLUTIONS
==============

* Create some data;
* FYI - I compress out blanks with one function key;
data have;
input
CA Item $ CA1 SAL $;
cards4;
12356 NO 856 YES
34527 YES 245 2.56
56789 1 123 3.2
;;;;
run;quit;

FULL SOLUTION
=============

proc transpose data=have out=havxpo;
by ca;
var _all_;
run;quit;

/*
Up to 40 obs WORK.HAVXPO total obs=12

Obs      CA     _NAME_        COL1

  1    12356     CA              12356
  2    12356     ITEM     NO
  3    12356     CA1               856
  4    12356     SAL      YES
  5    34527     CA              34527
  6    34527     ITEM     YES
  7    34527     CA1               245
  8    34527     SAL      2.56
  9    56789     CA              56789
 10    56789     ITEM     1
 11    56789     CA1               123
 12    56789     SAL      3.2
*/

proc transpose data=havxpo out=havxpoxpo(drop=_name_);
by ca;
id _name_;
var col1;
run;quit;

/*
Up to 40 obs WORK.HAVXPOXPO total obs=3

Obs      CA     ITEM    CA1    SAL

 1     12356    NO      856    YES
 2     34527    YES     245    2.56
 3     56789    1       123    3.2
*/

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Nov 2016 20:28:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/314949#M61600</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-11-28T20:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: convert all numeric variables to charater at once</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/315018#M61607</link>
      <description>&lt;P&gt;Here's an alternative:&amp;nbsp; run two proc transposes, one for numerics (naming vars NUM1-NUMn)&amp;nbsp; and one for character (naming vars CHAR1-CHARn), where n is the number of observations in the source data set.&amp;nbsp;&amp;nbsp;Each of the result files will get the same number of variables (n,&amp;nbsp; excluding the new variable _NAME_).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then just SET them both, and convert NUM1-NUMn to character form in CHAR1-CHARn.&amp;nbsp; Drop the NUM: vars. &amp;nbsp;No need to determine how many variables of character vs numeric there are:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sashelp.class out=tn  prefix=num;
run;

proc transpose data=sashelp.class  out=tc  prefix=char;
  var _character_;
run;

data want;
  set tn (in=in_n) tc;
  array n {*} num: ;
  array c {*} char: ;
  if in_n then do I=1 to dim(n);
    c{I}=put(n{I},8.);
  end;
  drop num: I ;
run;  
  

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 00:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/convert-all-numeric-variables-to-charater-at-once/m-p/315018#M61607</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-29T00:38:14Z</dc:date>
    </item>
  </channel>
</rss>

