<?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: Concatenate all numeric columns with CATX in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-all-numeric-columns-with-CATX/m-p/709595#M218247</link>
    <description>&lt;P&gt;A modification of first &lt;STRONG&gt;may&lt;/STRONG&gt; work:&lt;/P&gt;
&lt;PRE&gt;data work.option1;
   x=3;
   y=345.678;
   z=55555;
   array ___c _numeric_;	
   concat_num = catx("/", of ___c(*));
run;&lt;/PRE&gt;
&lt;P&gt;How many potential variables are you concerned with? And how many digits? I suspect you may have two issues, one from a large number of numeric variables. The second is conversion of any decimal values. If you do not specify a format for the variable you may find the desired number of digits for some values truncated by a Best format.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jan 2021 10:57:56 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-01-06T10:57:56Z</dc:date>
    <item>
      <title>Concatenate all numeric columns with CATX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-all-numeric-columns-with-CATX/m-p/709590#M218243</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to concatenate all numeric columns with the CATX function, without specifying all columns names.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.my_ds;
	input char1 $ char2 $ num1 num2;
	datalines;
A Z 111 222
B Y 123 456
C X 987 654
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My first thought was to use CATX("/", of _numeric_). However, this doesn't work because of the data type of the new variable &lt;STRONG&gt;&lt;EM&gt;concat_num&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Option 1: Doesn't work */
data work.option1;
	set work.my_ds;
	
	concat_num = catx("/", of _numeric_);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The second option is to define the data type of&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;concat_num&lt;/EM&gt;&lt;/STRONG&gt;. This works, but I don't like the solution because you have to define directly the length of the new variable. The defined length might be too short or too long.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Option 2: Works, but you need to define the Length of concat_num variable */
data work.option2;
	set work.my_ds;
	
	length concat_num $20;
	concat_num = catx("/", of _numeric_);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The third option is to use the Dictionary tables to create a macro variable of all numeric columns. This option works fine, but might be hard to understand for someone who isn't very experienced in SAS.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Option 3: Works, but not very elegant. Hard to understand for less experienced programmer */
proc sql;
	select name into :numeric_vars
	separated by ","
	from dictionary.columns
	where libname="WORK"
	and memname="MY_DS"
	and type="num";
quit;

data work.option3;
	set work.my_ds;
	
	concat_num = catx("/", &amp;amp;numeric_vars.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Does anyone have a more elegant and easy-to-understand solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Pim&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 10:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-all-numeric-columns-with-CATX/m-p/709590#M218243</guid>
      <dc:creator>Mr_Kempe</dc:creator>
      <dc:date>2021-01-06T10:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate all numeric columns with CATX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-all-numeric-columns-with-CATX/m-p/709595#M218247</link>
      <description>&lt;P&gt;A modification of first &lt;STRONG&gt;may&lt;/STRONG&gt; work:&lt;/P&gt;
&lt;PRE&gt;data work.option1;
   x=3;
   y=345.678;
   z=55555;
   array ___c _numeric_;	
   concat_num = catx("/", of ___c(*));
run;&lt;/PRE&gt;
&lt;P&gt;How many potential variables are you concerned with? And how many digits? I suspect you may have two issues, one from a large number of numeric variables. The second is conversion of any decimal values. If you do not specify a format for the variable you may find the desired number of digits for some values truncated by a Best format.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 10:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-all-numeric-columns-with-CATX/m-p/709595#M218247</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-06T10:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate all numeric columns with CATX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-all-numeric-columns-with-CATX/m-p/709600#M218251</link>
      <description>&lt;P&gt;The question arises: why are all those columns numeric, when they are treated as character anyway?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The most elegant solution is the DICTIONARY solution, as It adapts well to changing numbers of columns, and you can expand it to calculate the length needed for the new variable, if the maximum number of digits per column is known.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 11:37:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-all-numeric-columns-with-CATX/m-p/709600#M218251</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-06T11:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate all numeric columns with CATX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-all-numeric-columns-with-CATX/m-p/709602#M218253</link>
      <description>&lt;P&gt;Please have look at the documentation of catx: "In a DATA step, if the CATX function returns a value to a variable that has not previously been assigned a length, that variable is given a length of 200 bytes." And if the concatenated values need more than 200 chars, you will get&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;WARNING: In a call to the CATX function, the buffer allocated for the result was not long enough to contain the &lt;BR /&gt;concatenation of all the arguments.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 11:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-all-numeric-columns-with-CATX/m-p/709602#M218253</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-01-06T11:42:49Z</dc:date>
    </item>
  </channel>
</rss>

