<?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 concatenate multiple variables from multiple rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-multiple-variables-from-multiple-rows/m-p/772498#M245292</link>
    <description>&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;And I have zero clue why, but posting SAS code in SAS Community doesn't always keep my "next" lines if that makes sense. My code will be on multiple lines, but will post as one. I didn't know 'cards' had to be on its own line though (I always just blindly copied it that way), so good to know!&lt;/P&gt;</description>
    <pubDate>Wed, 06 Oct 2021 17:20:18 GMT</pubDate>
    <dc:creator>mariko5797</dc:creator>
    <dc:date>2021-10-06T17:20:18Z</dc:date>
    <item>
      <title>How to concatenate multiple variables from multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-multiple-variables-from-multiple-rows/m-p/772478#M245282</link>
      <description>&lt;P&gt;I think it's easiest to describe my goal by showing the type of data I have and the format I want to go into. Is there a simple way to achieve this?&amp;nbsp;Thank you in advance!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mariko5797_0-1633537542449.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64409i6ACF588FE603288A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mariko5797_0-1633537542449.png" alt="mariko5797_0-1633537542449.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mariko5797_1-1633537560139.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64410i9195090226AB031F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mariko5797_1-1633537560139.png" alt="mariko5797_1-1633537560139.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Dummy dataset to use... &lt;U&gt;NOTE:&lt;/U&gt; I have zero clue on how to add missing values with this, so the dummy code would need to be tweaked. Sorry&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dummy;&lt;BR /&gt;input id incexc1 $9. type1 $ incexc2 $9. type2 $;&lt;BR /&gt;cards;&lt;BR /&gt;1 INCLUSION IN102 INCLUSION IN103&lt;BR /&gt;1 EXCLUSION EX103 INCLUSION IN112&lt;BR /&gt;2 INCLUSION IN106 &lt;BR /&gt;3 INCLUSION IN109 EXCLUSION EX106&lt;BR /&gt;3 INCLUSION IN102 &lt;BR /&gt;3 EXCLUSION EX104 &lt;BR /&gt;4 INCLUSION IN107 INCLUSION IN110&lt;BR /&gt;5 EXCLUSION EX106 INCLUSION IN101&lt;BR /&gt;5 EXCLUSION EX108 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My first attempt was the below code. Obviously this won't work b/c it will only concatenate what's in the same row not same ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dummy;
 set dummy;
 if not missing(incexl1) and missing(incexl2) then incexcrs = trim(incexl1);
	else if missing(incexl1) and not missing(incexl2) then incexcrs = trim(incexl2);
	else if not missing(incexl1) and not missing(incexl2) then incexcrs = trim(incexl1) ||', '|| trim(incexl2);
	else incexcrs = '';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Oct 2021 16:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-multiple-variables-from-multiple-rows/m-p/772478#M245282</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-10-06T16:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate multiple variables from multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-multiple-variables-from-multiple-rows/m-p/772481#M245283</link>
      <description>&lt;P&gt;Use the first approach outlined &lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_self"&gt;here&lt;/A&gt; (&lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_blank"&gt;https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a&lt;/A&gt;) for each column - TYPE1 and TYPE2 stored into TYPE1_LIST and TYPE2_LIST (note that in SAS you cannot have variables with the same name, so I'm assuming that you have different names than shown.&lt;/P&gt;
&lt;P&gt;Then combine them at the end by adding:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.ID then do;
 inc_excl_type = catt(type1_list, type2_list);
output;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 16:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-multiple-variables-from-multiple-rows/m-p/772481#M245283</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-06T16:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate multiple variables from multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-multiple-variables-from-multiple-rows/m-p/772489#M245289</link>
      <description>&lt;P&gt;Do you expect results in that exact order?&lt;/P&gt;
&lt;P&gt;That is much harder than providing both "types" from a single record first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example of a data step to read "missing" values from your "example". The dot character will be read as missing&lt;/P&gt;
&lt;P&gt;character value if the only character encountered.&lt;/P&gt;
&lt;PRE&gt;data dummy;
   input id incexc1 $9. type1 $ incexc2 $9. type2 $;
cards;
1 INCLUSION IN102 INCLUSION IN103
1 EXCLUSION EX103 INCLUSION IN112
2 INCLUSION IN106 .         .
3 INCLUSION IN109 EXCLUSION EX106
3 INCLUSION IN102 .         .
3 EXCLUSION EX104 .         .
4 INCLUSION IN107 INCLUSION IN110
5 EXCLUSION EX106 INCLUSION IN101
5 EXCLUSION EX108 .         .
;&lt;/PRE&gt;
&lt;P&gt;I don't know what you copied from to post that dummy data step but please review the next time you post one. What ever source seems not to have a proper end of line character.&lt;/P&gt;
&lt;P&gt;Card (or Datalines same thing) must appear on a line by itself as does the ; or ;;;; (with Cards4) to end the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 17:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-multiple-variables-from-multiple-rows/m-p/772489#M245289</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-06T17:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate multiple variables from multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-multiple-variables-from-multiple-rows/m-p/772498#M245292</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;And I have zero clue why, but posting SAS code in SAS Community doesn't always keep my "next" lines if that makes sense. My code will be on multiple lines, but will post as one. I didn't know 'cards' had to be on its own line though (I always just blindly copied it that way), so good to know!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 17:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-multiple-variables-from-multiple-rows/m-p/772498#M245292</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-10-06T17:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate multiple variables from multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-multiple-variables-from-multiple-rows/m-p/772501#M245294</link>
      <description>Typically this happens if you edit the code after you've posted in the code box but not in the code editor.</description>
      <pubDate>Wed, 06 Oct 2021 17:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-multiple-variables-from-multiple-rows/m-p/772501#M245294</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-06T17:34:05Z</dc:date>
    </item>
  </channel>
</rss>

