<?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: cat or catx unknow number of columns in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461733#M29768</link>
    <description>&lt;P&gt;if i understand your needs correctly, you could use variable lists with a common name prefix followed by a : (colon)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sashelp.class out=want;
var name;
run;

data w;
set want;
k=catx('__',of col:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 12 May 2018 00:14:03 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-05-12T00:14:03Z</dc:date>
    <item>
      <title>cat or catx unknow number of columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461732#M29767</link>
      <description>&lt;P&gt;I just proc transposed my data and its giving me Column1 to ColumnX and the x number will keep changing how do i do a Catx( ) calculation when i dont know the number of columns&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 May 2018 00:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461732#M29767</guid>
      <dc:creator>hk2013</dc:creator>
      <dc:date>2018-05-12T00:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: cat or catx unknow number of columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461733#M29768</link>
      <description>&lt;P&gt;if i understand your needs correctly, you could use variable lists with a common name prefix followed by a : (colon)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sashelp.class out=want;
var name;
run;

data w;
set want;
k=catx('__',of col:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 May 2018 00:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461733#M29768</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-12T00:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: cat or catx unknow number of columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461735#M29769</link>
      <description>I have tried that but it doesn’t seem to work. The transpose give data as column1,column2...&lt;BR /&gt;And I have tried x=catx(' ‘,of column:); but it does not work.&lt;BR /&gt;</description>
      <pubDate>Sat, 12 May 2018 00:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461735#M29769</guid>
      <dc:creator>hk2013</dc:creator>
      <dc:date>2018-05-12T00:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: cat or catx unknow number of columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461736#M29770</link>
      <description>&lt;P&gt;Please show us the community a sample of your data, your code , log and your expected output so that somebody will be able to help you&lt;/P&gt;</description>
      <pubDate>Sat, 12 May 2018 00:38:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461736#M29770</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-12T00:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: cat or catx unknow number of columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461746#M29771</link>
      <description>&lt;P&gt;Proc Transpose allows you to specify a custom prefix, for example PRE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use that and make sure it doesn’t interfere with your other variable name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then use the OF and colon as indicated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;New = catt(of PRE:);

New2 = catx('-', of PRE:);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 May 2018 02:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461746#M29771</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-12T02:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: cat or catx unknow number of columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461748#M29772</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169082"&gt;@hk2013&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Keyword &lt;EM&gt;PREFIX&lt;/EM&gt; in Proc Transpose allows you to define how transposed variables get called.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code like below should work - else please post representative sample data, and your code (please test that the code works for the sample data) and show us where things aren't working for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sashelp.class out=transposed prefix=NEWCOL_;
  var name;
run;

/* determine required length for variable holding the concatenated string */
proc sql noprint;
  select put(sum(length)+count(*),best32. -l) into :string_length
  from dictionary.columns
  where 
    libname='WORK' 
    and memname='TRANSPOSED' 
    and upcase(name) like 'NEWCOL^_%' escape '^'
  ;
quit;

/* create ds with variable holding the concatenated string */
data want;
  set transposed;
  length k $&amp;amp;string_length.;
  k=catx('|',of NEWCOL_:);
  drop NEWCOL_:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 May 2018 02:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461748#M29772</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-05-12T02:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: cat or catx unknow number of columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461771#M29773</link>
      <description>&lt;P&gt;As long as you need a DATA step to combine all the transposed values, why not just skip PROC TRANSPOSE?&amp;nbsp; You can certainly use a DATA step on the original data, to get the same effect.&amp;nbsp; The variable names are unknown, so here's a guess as to what the program might look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by state;&lt;/P&gt;
&lt;P&gt;length all_values $ 2000;&lt;/P&gt;
&lt;P&gt;if first.state then all_values = result;&lt;/P&gt;
&lt;P&gt;else all_values = catx('|', all_values, result);&lt;/P&gt;
&lt;P&gt;if last.state;&lt;/P&gt;
&lt;P&gt;run;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 May 2018 12:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/461771#M29773</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-12T12:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: cat or catx unknow number of columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/462074#M29794</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169082"&gt;@hk2013&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I just proc transposed my data and its giving me Column1 to ColumnX and the x number will keep changing how do i do a Catx( ) calculation when i dont know the number of columns&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you do not know how many variables you will be CATing together how do you know how long to make the variable that is the target?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the documentation:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;In a DATA step, if the &lt;FONT style="background-color: rgb(252, 222, 192);"&gt;CATX&lt;/FONT&gt; function returns a value to a variable that has not previously been assigned a length, then that variable is given a length of 200 bytes&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The other CAT functions are similar.&lt;/P&gt;
&lt;P&gt;So if you have 25 variables of length 9 + inserting comma you need 25*9+24=249 characters minimum length to store the result. So it may be that your result will be truncated because you do not have enough length for the concatenated string. I suggest finding a step to determine how long you need that CATX result to be or else you'll be back saying&amp;nbsp; "it didn't work".&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, 14 May 2018 15:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/462074#M29794</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-14T15:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: cat or catx unknow number of columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/462231#M29812</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169082"&gt;@hk2013&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I just proc transposed my data and its giving me Column1 to ColumnX and the x number will keep changing how do i do a Catx( ) calculation when i dont know the number of columns&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/169082"&gt;@hk2013&lt;/a&gt; That's why I've added this proc SQL step in my previous post which calculates the required length.&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 23:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/cat-or-catx-unknow-number-of-columns/m-p/462231#M29812</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-05-14T23:46:20Z</dc:date>
    </item>
  </channel>
</rss>

