<?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: How to all values separated by comma in one row by id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-all-values-separated-by-comma-in-one-row-by-id/m-p/773865#M245897</link>
    <description>&lt;P&gt;try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input MUS_NO SERVICE $;
cards;
22222 a
22222 b
22222 b
11111 x
11111 y
33333 a
33333 b
33333 c
33333 d
33333 e
;
run;
proc sort data = have;
  by MUS_NO SERVICE;
run;

data want;
  do until(last.MUS_NO);
    set have;
    by MUS_NO;
    length list_service $ 100;
    list_service = catx(",", list_service, SERVICE);
  end;

  output;
  keep MUS_NO list_service;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Oct 2021 09:06:59 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2021-10-13T09:06:59Z</dc:date>
    <item>
      <title>How to all values separated by comma in one row by id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-all-values-separated-by-comma-in-one-row-by-id/m-p/773863#M245895</link>
      <description>&lt;P&gt;Hi to everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have similar the data below;&lt;/P&gt;&lt;P&gt;MUS_NO&amp;nbsp; SERVICE&lt;/P&gt;&lt;P&gt;22222&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a&lt;BR /&gt;22222&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b&lt;BR /&gt;22222&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b&lt;BR /&gt;11111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x&lt;BR /&gt;11111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;y&lt;BR /&gt;33333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a&lt;BR /&gt;33333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b&lt;BR /&gt;33333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c&lt;BR /&gt;33333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;d&lt;BR /&gt;33333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and i'd like to convert into these table;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;MUST_NO list_service&lt;BR /&gt;11111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x,y&lt;BR /&gt;22222&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a,b,b&lt;BR /&gt;33333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a,b,c,d,e&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually i could obtain the last table by using transpoze and cat function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*sorting before transpoze step*/&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE SAS_EXAMPLE AS&lt;BR /&gt;SELECT * FROM SAS_EXAMPLE&lt;BR /&gt;ORDER BY MUS_NO ASC,SERVICE ASC;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*transpozing by mus_no*/&lt;BR /&gt;PROC TRANSPOZE DATA=SAS_EXAMPLE OUT=SAS_EXAMPLE_2 PREFIX=col;&lt;BR /&gt;BY MUS_NO;&lt;BR /&gt;VAR SERVICE;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*combining transpozed columns with comma and deleting unnecessary columns*/&lt;BR /&gt;DATA SAS_EXAMPLE_3;&lt;BR /&gt;SET SAS_EXAMPLE_2;&lt;BR /&gt;LENGTH list_service $200;&lt;BR /&gt;list_service=catx(',',of col:);&lt;BR /&gt;DROP _NAME_ col1--col5/*should write max number of obs for a must_no. For this case 5 for mus_no 33333*/;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I have thousands rows for a customer so i donot want to use transpoze procedure so i tried to use these code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data list;&lt;/P&gt;&lt;P&gt;set WORK.QUERY_FOR_SAS_EXAMPLE_LIST;&lt;/P&gt;&lt;P&gt;by mus_no;&lt;/P&gt;&lt;P&gt;retain list_service;&lt;BR /&gt;if first.mus_no then list_service_k=1; else list_service_k=0;&lt;BR /&gt;if first.mus_no then list_service=service;&lt;BR /&gt;&lt;BR /&gt;list_service_a = catx(",",service,list_service);&lt;BR /&gt;list_service=list_service_a;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But i can't. How can i obtain this table i want?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 08:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-all-values-separated-by-comma-in-one-row-by-id/m-p/773863#M245895</guid>
      <dc:creator>senfonik</dc:creator>
      <dc:date>2021-10-13T08:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to all values separated by comma in one row by id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-all-values-separated-by-comma-in-one-row-by-id/m-p/773864#M245896</link>
      <description>&lt;P&gt;You need to make the target variable large enough; keep in mind that even with the maximum size of character variables, you may not be able to hold all values given that you have "thousand&lt;STRONG&gt;s&lt;/STRONG&gt;" of rows per customer:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by mus_no notsorted;
length list_service $32767;
retain list_service;
if first.mus_no then list_service = "";
list_service = catx(",",list_service,service);
if last.mus_no;
keep mus_no list_service;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The question arises: what for do you need this monster string?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 09:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-all-values-separated-by-comma-in-one-row-by-id/m-p/773864#M245896</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-13T09:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to all values separated by comma in one row by id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-all-values-separated-by-comma-in-one-row-by-id/m-p/773865#M245897</link>
      <description>&lt;P&gt;try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input MUS_NO SERVICE $;
cards;
22222 a
22222 b
22222 b
11111 x
11111 y
33333 a
33333 b
33333 c
33333 d
33333 e
;
run;
proc sort data = have;
  by MUS_NO SERVICE;
run;

data want;
  do until(last.MUS_NO);
    set have;
    by MUS_NO;
    length list_service $ 100;
    list_service = catx(",", list_service, SERVICE);
  end;

  output;
  keep MUS_NO list_service;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 09:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-all-values-separated-by-comma-in-one-row-by-id/m-p/773865#M245897</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-10-13T09:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to all values separated by comma in one row by id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-all-values-separated-by-comma-in-one-row-by-id/m-p/773868#M245898</link>
      <description>&lt;P&gt;thank you very much!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 09:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-all-values-separated-by-comma-in-one-row-by-id/m-p/773868#M245898</guid>
      <dc:creator>senfonik</dc:creator>
      <dc:date>2021-10-13T09:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to all values separated by comma in one row by id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-all-values-separated-by-comma-in-one-row-by-id/m-p/773869#M245899</link>
      <description>thank you very much!</description>
      <pubDate>Wed, 13 Oct 2021 09:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-all-values-separated-by-comma-in-one-row-by-id/m-p/773869#M245899</guid>
      <dc:creator>senfonik</dc:creator>
      <dc:date>2021-10-13T09:17:41Z</dc:date>
    </item>
  </channel>
</rss>

