<?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: Combine Multiple Rows' Values into One Field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/408008#M99491</link>
    <description>&lt;P&gt;You need to retain the &lt;EM&gt;new&lt;/EM&gt; variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testdave1;
set testdave;
retain concat;
by PART_NAME;
length concat $30.;
if first.PART_NAME then concat = "";
concat = catx('/',concat,claim_cat);
if last.PART_NAME then output;
drop claim_cat;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The trim() functions are actually not necessary, as catx() does that automatically.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Oct 2017 13:03:03 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-10-27T13:03:03Z</dc:date>
    <item>
      <title>Combine Multiple Rows' Values into One Field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/407987#M99478</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;This should be pretty simple but I'm having difficulty figuring it out.&amp;nbsp; I'm trying to combine values from multiple observations into one field.&amp;nbsp; From the first table below to the 2nd.&amp;nbsp; Note that in some instances 'PART1' could have only one record, sometimes 2 and sometimes 3 so the code would have to be written to accommodate this.&amp;nbsp; I've shown it with PART1 having 3 records below.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;PART_NAME&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;CLAIM_CAT&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PART1&lt;/TD&gt;&lt;TD&gt;EXT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PART1&lt;/TD&gt;&lt;TD&gt;STD&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PART1&lt;/TD&gt;&lt;TD&gt;PURCH&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;PART_NAME&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;CLAIM_CAT&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PART1&lt;/TD&gt;&lt;TD&gt;EXT/STD/PURCH&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated!!!&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 12:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/407987#M99478</guid>
      <dc:creator>bendsteel6</dc:creator>
      <dc:date>2017-10-27T12:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Multiple Rows' Values into One Field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/407990#M99479</link>
      <description>&lt;P&gt;First of all, you have to create a new variable with sufficient length.&lt;/P&gt;
&lt;P&gt;In a data step, retain this new variable.&lt;/P&gt;
&lt;P&gt;Use by part_name;&lt;/P&gt;
&lt;P&gt;At first.part_name, set the new variable to empty&lt;/P&gt;
&lt;P&gt;Concatenate by using newvar = catx('/',trim(newvar),claim_cat);&lt;/P&gt;
&lt;P&gt;At last.part_name, output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That should do it.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 12:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/407990#M99479</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-27T12:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Multiple Rows' Values into One Field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/407999#M99486</link>
      <description>&lt;P&gt;Hi.&amp;nbsp; Thanks for your input.&amp;nbsp; I'm trying this but I just keep getting the same value in the new field as in the old...Here's the code (with some variable name changes to suit my actual data).&amp;nbsp; I must be doing something wrong...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;PART_NAME&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;CLAIM_CAT&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;EGR COOLER, REPLACEMENT KIT&lt;/TD&gt;&lt;TD&gt;EXT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;EGR COOLER, REPLACEMENT KIT&lt;/TD&gt;&lt;TD&gt;STD&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;EGR COOLER, REPLACEMENT KIT&lt;/TD&gt;&lt;TD&gt;PURCH&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; testdave1;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; testdave;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;retain&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; PART_NAME;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; PART_NAME;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; concat &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New"&gt;$30.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; first.PART_NAME &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; concat=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;""&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT face="Courier New"&gt;concat=catx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;'/'&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;,trim(concat),trim(claim_cat));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; last.PART_NAME &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;FONT face="Courier New"&gt;Results:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;PART_NAME&lt;/TD&gt;&lt;TD&gt;CLAIM_CAT&lt;/TD&gt;&lt;TD&gt;concat&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;EGR COOLER, REPLACEMENT KIT&lt;/TD&gt;&lt;TD&gt;PURCH&lt;/TD&gt;&lt;TD&gt;PURCH&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 27 Oct 2017 12:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/407999#M99486</guid>
      <dc:creator>bendsteel6</dc:creator>
      <dc:date>2017-10-27T12:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Multiple Rows' Values into One Field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/408008#M99491</link>
      <description>&lt;P&gt;You need to retain the &lt;EM&gt;new&lt;/EM&gt; variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testdave1;
set testdave;
retain concat;
by PART_NAME;
length concat $30.;
if first.PART_NAME then concat = "";
concat = catx('/',concat,claim_cat);
if last.PART_NAME then output;
drop claim_cat;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The trim() functions are actually not necessary, as catx() does that automatically.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 13:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/408008#M99491</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-27T13:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Multiple Rows' Values into One Field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/408010#M99492</link>
      <description>&lt;P&gt;Ahhhhhhh...yes!&amp;nbsp; Duhhh!!!&amp;nbsp; I should've seen that.&amp;nbsp; Works like a charm, saves me so much code writing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THANK YOU!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 13:05:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/408010#M99492</guid>
      <dc:creator>bendsteel6</dc:creator>
      <dc:date>2017-10-27T13:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Multiple Rows' Values into One Field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/837814#M331287</link>
      <description>&lt;P&gt;How would you do this but prevent duplicates in the output column.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 10:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-Multiple-Rows-Values-into-One-Field/m-p/837814#M331287</guid>
      <dc:creator>danidull</dc:creator>
      <dc:date>2022-10-11T10:49:37Z</dc:date>
    </item>
  </channel>
</rss>

