<?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: Looping and Concat col in QB in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335980#M22323</link>
    <description>&lt;P&gt;i See. thx you for your help&amp;nbsp; &lt;img id="manvery-happy" class="emoticon emoticon-manvery-happy" src="https://communities.sas.com/i/smilies/16x16_man-very-happy.png" alt="Man Very Happy" title="Man Very Happy" /&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 26 Feb 2017 14:30:27 GMT</pubDate>
    <dc:creator>SASNE</dc:creator>
    <dc:date>2017-02-26T14:30:27Z</dc:date>
    <item>
      <title>Looping and Concat col in QB</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335958#M22312</link>
      <description>&lt;P&gt;Hi Gurus,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let say&amp;nbsp;&amp;nbsp; If i have a Column 1 to Column 100 and want to group them by Col-Fruit, in order word i want to concat&amp;nbsp; Col1 to Col100 in Query builder, I would select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Col-Fruit under Select&amp;nbsp; Data and Add computed column with&amp;nbsp; " Catx(',', Col1,Col2,Col3........Col100)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;are there any smart to loop or something that i don't have to type from Col1 to Col100 ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank for your help in advance&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 07:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335958#M22312</guid>
      <dc:creator>SASNE</dc:creator>
      <dc:date>2017-02-26T07:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Looping and Concat col in QB</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335960#M22313</link>
      <description>&lt;P&gt;There are limits to point-and-click interfaces.&lt;/P&gt;
&lt;P&gt;Generating such repeating code in a macro is a breeze:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro concat(number);
data want;
set have;
length new_field $1000;
new_field = catx(','
%do i = 1 %to &amp;amp;number;
,col&amp;amp;i.
%end;
);
run;
%mend;
%concat(100)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can create the code with call execute:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call execute('data want; set have; length new_field $1000; new_field = catx(","');
do i = 1 to 100;
  call execute(',col'!!strip(put(i,3.)));
end;
call execute('); run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Feb 2017 08:12:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335960#M22313</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-26T08:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: Looping and Concat col in QB</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335961#M22314</link>
      <description>&lt;P&gt;Thx, KurtBremser.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yeah ,same as last time, would like to know how to do it in Sas EG &lt;img id="manvery-happy" class="emoticon emoticon-manvery-happy" src="https://communities.sas.com/i/smilies/16x16_man-very-happy.png" alt="Man Very Happy" title="Man Very Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 08:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335961#M22314</guid>
      <dc:creator>SASNE</dc:creator>
      <dc:date>2017-02-26T08:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Looping and Concat col in QB</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335963#M22315</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127317"&gt;@SASNE&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thx, KurtBremser.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yeah ,same as last time, would like to know how to do it in Sas EG &lt;img id="manvery-happy" class="emoticon emoticon-manvery-happy" src="https://communities.sas.com/i/smilies/16x16_man-very-happy.png" alt="Man Very Happy" title="Man Very Happy" /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Simple. Open a code node and write the code.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 08:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335963#M22315</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-26T08:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: Looping and Concat col in QB</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335969#M22319</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Catx(',', of Col1-Col100)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 10:26:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335969#M22319</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-02-26T10:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Looping and Concat col in QB</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335979#M22322</link>
      <description>&lt;P&gt;Unfortunately there are no shortcuts within SAS EG or PROC SQL. Data steps allow for variable shortcut lists as illustrated by KSharp.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 13:33:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335979#M22322</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-26T13:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: Looping and Concat col in QB</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335980#M22323</link>
      <description>&lt;P&gt;i See. thx you for your help&amp;nbsp; &lt;img id="manvery-happy" class="emoticon emoticon-manvery-happy" src="https://communities.sas.com/i/smilies/16x16_man-very-happy.png" alt="Man Very Happy" title="Man Very Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 14:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335980#M22323</guid>
      <dc:creator>SASNE</dc:creator>
      <dc:date>2017-02-26T14:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: Looping and Concat col in QB</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/336090#M22331</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Looping and Concat col in QB

This problem does not lend itself to mouse surfing?

inspired by
https://goo.gl/C5qmVX
https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/335958


This solution is a bit advanced and probably
should not be used by inexperienced programmers.

You do not need to know how many columns are in the data.


HAVE
====

Up to 40 obs WORK.HAVE total obs=5

 O COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8 COL9 COL10 FRUIT

 1 A086 A090 A098 A002 A083 A042 A031 A090 A091 A088 APPLE
 2 A055 A008 A014 A031 A074 A066 A084 A000 A024 A062 APPLE
 3 A071 A004 A010 A038 A006 A044 A054 A033 A039 A085 APPLE
 4 A057 A047 A098 A010 A024 A002 A041 A073 A025 A046 APPLE
 5 A081 A098 A052 A099 A036 A081 A069 A048 A024 A040 APPLE

WANT
====

COLALL                                                        FRUIT
-------------------------------------------------------------------
A086,A090,A098,A002,A083,A042,A031,A090,A091,A088             APPLE
A055,A008,A014,A031,A074,A066,A084,A000,A024,A062             APPLE
A071,A004,A010,A038,A006,A044,A054,A033,A039,A085             APPLE
A057,A047,A098,A010,A024,A002,A041,A073,A025,A046             APPLE
A081,A098,A052,A099,A036,A081,A069,A048,A024,A040             APPLE

WORKING CODE

   rc=dosubl('
   proc sql;
     select
       catx(",",&amp;amp;colcat.) as colall length=44
      ,fruit
     from
       have
     ;quit;
');


FULL SOLUTION
=============

* create some data;
data have;
 array cols[10] $8 col1-col10;
 do rep=1 to 5;
    do var= 1 to 10;
       cols[var]='A'!!put(int(100*uniform(-1)),z3.);
    end;
    fruit='APPLE';
    keep c: fruit;
    output;
 end;
run;quit;

* select concatenated cols and fruit;
data null_;
 length getcol $1024;
 set have(obs=1);
 array cols[*] c:;
 do i=1 to dim(cols);
  getcol=catx(',',getcol,vname(cols[i]));
 end;
 call symputx('colcat',strip(getcol));
 put getcol=;
 rc=dosubl('
   proc sql;
     select
       catx(",",&amp;amp;colcat.) as colall length=60
      ,fruit
     from
       have
   ;quit;
');
 stop;
run;quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Feb 2017 02:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-and-Concat-col-in-QB/m-p/336090#M22331</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-02-27T02:47:29Z</dc:date>
    </item>
  </channel>
</rss>

