<?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 a macro to automate the catx function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226539#M40777</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for all your help guys. I've gone with catx(" : ", of a1-a&amp;amp;maxcount) and it's worked a treat.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
    <pubDate>Mon, 21 Sep 2015 10:48:48 GMT</pubDate>
    <dc:creator>mbyxcb1</dc:creator>
    <dc:date>2015-09-21T10:48:48Z</dc:date>
    <item>
      <title>Using a macro to automate the catx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226341#M40731</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have multiple variables that I want to join together using the catx function. However, this code is placed within a larger program where the number of start variables is likely to grow over time so I would like&amp;nbsp;to automate it. The current code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;proc &lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;sql&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;create&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;table&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt; new_table &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;s&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;elect&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt; *,&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;catx(&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;" : "&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10&lt;/FONT&gt;&lt;/FONT&gt;) &lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt; list&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;from&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt; old_table&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;q&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;uit&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;I'd like to automate this to something equivalent to:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;proc &lt;FONT size="2"&gt;sql&lt;/FONT&gt;&lt;FONT size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;create&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;table&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt; new_table &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;as&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;s&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;elect&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt; *,&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;do i = 1 to &amp;amp;maxcount;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;catx(" : ",a&amp;amp;i) as list&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;end;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;from old_table&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;quit;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;Where &amp;amp;maxcount is an already created macro variable containing the correct number of varibales present in the dataset. However, everything I've tried doesn't seem to have the desired effect. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="andale mono,times"&gt;&lt;FONT size="2"&gt;&lt;FONT size="2"&gt;Any help would be much appreciated. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 15:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226341#M40731</guid>
      <dc:creator>mbyxcb1</dc:creator>
      <dc:date>2015-09-18T15:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro to automate the catx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226348#M40735</link>
      <description>&lt;P&gt;You would be better served using a DATA step instead of SQL as you can the use the 'of' operator in CATX() to specify a variable-list or range&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data foo;
array a[10] $1 (10*'a');
run;

data bar;
set foo;
list = catx(':',of a:);
run;&lt;BR /&gt;&lt;BR /&gt;/* &lt;BR /&gt;or&lt;BR /&gt;list = catx(':',of a1-a&amp;amp;maxcount.);&lt;BR /&gt;or&lt;BR /&gt;array a[&amp;amp;maxcount.];&lt;BR /&gt;list = catx(':',of a[*]);&lt;BR /&gt;*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2015 21:52:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226348#M40735</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2015-09-18T21:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro to automate the catx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226351#M40736</link>
      <description>&lt;P&gt;UNTESTED CODE, and it must be inside a SAS macro or %do and %if won't work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000" size="2"&gt;proc sql;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000" size="2"&gt;create table new_table as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000" size="2"&gt;select *, catx(" : ",&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000" size="2"&gt;%do i = 1 %to &amp;amp;maxcount; a&amp;amp;xi %if &amp;amp;i &amp;lt; &amp;amp;maxcount %then %str(,); %end;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000" size="2"&gt;as list&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000" size="2"&gt;from old_table&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000" size="2"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 16:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226351#M40736</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-09-18T16:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro to automate the catx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226358#M40737</link>
      <description>Similar to FriedEgg's solution&lt;BR /&gt;This should work as well&lt;BR /&gt;&lt;BR /&gt;catx(":", of a1-a&amp;amp;maxcount)</description>
      <pubDate>Fri, 18 Sep 2015 17:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226358#M40737</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-09-18T17:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro to automate the catx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226375#M40741</link>
      <description>&lt;P&gt;Don't need a macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA have;&lt;BR /&gt;infile cards dsd;&lt;BR /&gt;INPUT var1$ var2$ var3$ var4$ var5$;&lt;BR /&gt;cards;&lt;BR /&gt;one,two,three,four,five&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;%let max = 5;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;List = catx(":",of var1-var&amp;amp;max);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 18:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226375#M40741</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2015-09-18T18:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using a macro to automate the catx function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226539#M40777</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for all your help guys. I've gone with catx(" : ", of a1-a&amp;amp;maxcount) and it's worked a treat.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2015 10:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-macro-to-automate-the-catx-function/m-p/226539#M40777</guid>
      <dc:creator>mbyxcb1</dc:creator>
      <dc:date>2015-09-21T10:48:48Z</dc:date>
    </item>
  </channel>
</rss>

