<?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 Concatenate values by other values in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651426#M19257</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Please find attached the table that will illustrate my problem. I'd like that for each value of my variable PUIS_CLASS, I have the variable NEW which is the concatenation of all the values of&amp;nbsp;GROUPEACT occuring when the&amp;nbsp; PUIS_CLASS value is observed.&lt;BR /&gt;&lt;BR /&gt;For instance, the two first lines would be :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PUISS_CLASS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;GROUPEACT&lt;/P&gt;
&lt;P&gt;1_K&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "20_24_25_26_27_28"&lt;/P&gt;
&lt;P&gt;2_L&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"24_25_27"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;etc...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 May 2020 15:30:24 GMT</pubDate>
    <dc:creator>Mathis1</dc:creator>
    <dc:date>2020-05-28T15:30:24Z</dc:date>
    <item>
      <title>Concatenate values by other values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651426#M19257</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Please find attached the table that will illustrate my problem. I'd like that for each value of my variable PUIS_CLASS, I have the variable NEW which is the concatenation of all the values of&amp;nbsp;GROUPEACT occuring when the&amp;nbsp; PUIS_CLASS value is observed.&lt;BR /&gt;&lt;BR /&gt;For instance, the two first lines would be :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PUISS_CLASS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;GROUPEACT&lt;/P&gt;
&lt;P&gt;1_K&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "20_24_25_26_27_28"&lt;/P&gt;
&lt;P&gt;2_L&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"24_25_27"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;etc...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 15:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651426#M19257</guid>
      <dc:creator>Mathis1</dc:creator>
      <dc:date>2020-05-28T15:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate values by other values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651431#M19258</link>
      <description>&lt;P&gt;In a SAS DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want = cats(puiss_class,groupeact);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2020 15:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651431#M19258</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-28T15:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate values by other values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651436#M19259</link>
      <description>&lt;P&gt;Unfortunately, that is not what i want &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 15:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651436#M19259</guid>
      <dc:creator>Mathis1</dc:creator>
      <dc:date>2020-05-28T15:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate values by other values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651456#M19260</link>
      <description>&lt;PRE&gt;data want;
   set have;
   by puiss_class;&lt;BR /&gt;   length group $ 200;
   retain group;
   if first.puiss_class then call missing(group);
   value=catx('_',group, groupeact);
  if last.puiss_class;&lt;BR /&gt;  drop groupeact;
run;&lt;/PRE&gt;
&lt;P&gt;Since we need to reference two variable, the combined version and the starting version we cannot place the results directly into Groupeact as you imply. For one thing the existing variable is too short hold the combined values. You can adjust the length of the Group variable to be a better fit, or longer if needed.&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 16:17:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651456#M19260</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-28T16:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate values by other values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651458#M19261</link>
      <description>&lt;P&gt;This works, though there may be a simpler way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(&lt;EM&gt;Edit: Per your original question, modified&lt;/EM&gt;&lt;EM&gt;&amp;nbsp;to use NEW as the target variable.)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=hello_sas;
    by puis_class;
run;

data hello_sas_concat;
    set hello_sas;
    by puis_class;

    retain concat;
    
    if first.puis_class then
        concat = cats(groupeact, "");

    else if not(last.puis_class) then
        concat = cats(concat, "_", groupeact);

    else
        NEW = cats(concat, "_", groupeact);
    
    drop concat;
run;

data want (keep=puis_class NEW);
    set hello_sas_concat;
    where NEW is not null;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 18:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651458#M19261</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-05-28T18:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate values by other values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651462#M19262</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/323613"&gt;@Mathis1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=hello_sas;
	by PUIS_CLASS;
run;

data want;
	set hello_sas;
	by PUIS_CLASS;
	length GROUPEACT2 $ 100;
	retain GROUPEACT2;
	if first.PUIS_CLASS then GROUPEACT2 = GROUPEACT;
	else GROUPEACT2 = catx("_", GROUPEACT2, GROUPEACT);
	if last.PUIS_CLASS then output;
	drop GROUPEACT;
	rename GROUPEACT2=GROUPEACT;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2020 16:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651462#M19262</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-28T16:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate values by other values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651463#M19263</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need;
 do until(last.PUIS_CLASS);
  set hello_sas;
  by PUIS_CLASS  notsorted;
  length GROUPEACT_  $100;
  GROUPEACT_=catx('_', GROUPEACT_, GROUPEACT);
 end;
 drop GROUPEACT;
 rename GROUPEACT_=GROUPEACT;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2020 16:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651463#M19263</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-28T16:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate values by other values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651468#M19264</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/323613"&gt;@Mathis1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Unfortunately, that is not what i want &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then explain what you do want. Your original message never showed the desired output.&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 16:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651468#M19264</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-28T16:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate values by other values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651476#M19265</link>
      <description>&lt;P&gt;Unlike others, this is a multi step solution but I have kept it simple. You may have to sort your dataset first by PUIS_CLASS.&lt;/P&gt;
&lt;PRE&gt;proc transpose 
     data = have 
     out=Wanting 
     prefix=_c ;
    by puis_class ;
    var groupeact ;
run ;

data want ;
   set wanting ;
   length groupeact $2000 ;
   groupeact = quote(catx(",", of _c:)) ;
   drop _: ;
run ;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 16:58:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651476#M19265</guid>
      <dc:creator>biopharma</dc:creator>
      <dc:date>2020-05-28T16:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate values by other values</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651479#M19266</link>
      <description>I used the wrong separator value. This line should read:&lt;BR /&gt;groupeact = quote(catx("_", of _c:)) ;</description>
      <pubDate>Thu, 28 May 2020 17:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Concatenate-values-by-other-values/m-p/651479#M19266</guid>
      <dc:creator>biopharma</dc:creator>
      <dc:date>2020-05-28T17:01:29Z</dc:date>
    </item>
  </channel>
</rss>

