<?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: merge two rows data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merge-two-rows-data/m-p/562108#M157431</link>
    <description>&lt;P&gt;Here are the two most common methods:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;*create sample data for demonstration;
data have;
    infile cards dlm='09'x;
    input OrgID Product $   States $;
    cards;
1   football    DC
1   football    VA
1   football    MD
2   football    CA
3   football    NV
3   football    CA
;
run;

*Sort - required for both options;
proc sort data=have;
    by orgID;
run;

**********************************************************************;
*Use RETAIN and BY group processing to combine the information;
**********************************************************************;
data want_option1;
    set have;
    by orgID;
    length combined $100.;
    retain combined;

    if first.orgID then
        combined=states;
    else
        combined=catx(', ', combined, states);

    if last.orgID then
        output;
run;

**********************************************************************;
*Transpose it to a wide format and then combine into a single field;
**********************************************************************;
proc transpose data=have out=wide prefix=state_;
    by orgID;
    var states;
run;

data want_option2;
    set wide;
    length combined $100.;
    combined=catx(', ', of state_:);
run;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_blank"&gt;https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192083"&gt;@radha009&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;i have data like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;request parent number&lt;/P&gt;
&lt;P&gt;123&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 234&amp;nbsp; &amp;nbsp; &amp;nbsp; 789&lt;/P&gt;
&lt;P&gt;123&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 234&amp;nbsp; &amp;nbsp; &amp;nbsp; 545&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want to merge like&lt;/P&gt;
&lt;P&gt;request parent number&lt;/P&gt;
&lt;P&gt;123 234 789/545&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how to code this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 May 2019 20:56:01 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-05-28T20:56:01Z</dc:date>
    <item>
      <title>merge two rows data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-rows-data/m-p/562093#M157424</link>
      <description>&lt;P&gt;i have data like below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;request parent number&lt;/P&gt;&lt;P&gt;123&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 234&amp;nbsp; &amp;nbsp; &amp;nbsp; 789&lt;/P&gt;&lt;P&gt;123&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 234&amp;nbsp; &amp;nbsp; &amp;nbsp; 545&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;want to merge like&lt;/P&gt;&lt;P&gt;request parent number&lt;/P&gt;&lt;P&gt;123 234 789/545&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how to code this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 19:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-rows-data/m-p/562093#M157424</guid>
      <dc:creator>radha009</dc:creator>
      <dc:date>2019-05-28T19:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: merge two rows data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-rows-data/m-p/562097#M157426</link>
      <description>&lt;P&gt;I always get the feeling that the generalizations I make when the problem is shown with a very small number of records (in this case 2 records) will not hold for larger data sets. So it would certainly help if you provided a larger data set with more conditions. Nevertheless, what you ask for is provided as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
	input request parent number;
	cards;
	123 234 789
	123 234 545
;
proc transpose data=a out=b;
    by request parent;
run;
data want;
    set b;
	number = catx('/',col1,col2);
	drop _name_ col1 col2;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 20:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-rows-data/m-p/562097#M157426</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-28T20:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: merge two rows data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-rows-data/m-p/562108#M157431</link>
      <description>&lt;P&gt;Here are the two most common methods:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;*create sample data for demonstration;
data have;
    infile cards dlm='09'x;
    input OrgID Product $   States $;
    cards;
1   football    DC
1   football    VA
1   football    MD
2   football    CA
3   football    NV
3   football    CA
;
run;

*Sort - required for both options;
proc sort data=have;
    by orgID;
run;

**********************************************************************;
*Use RETAIN and BY group processing to combine the information;
**********************************************************************;
data want_option1;
    set have;
    by orgID;
    length combined $100.;
    retain combined;

    if first.orgID then
        combined=states;
    else
        combined=catx(', ', combined, states);

    if last.orgID then
        output;
run;

**********************************************************************;
*Transpose it to a wide format and then combine into a single field;
**********************************************************************;
proc transpose data=have out=wide prefix=state_;
    by orgID;
    var states;
run;

data want_option2;
    set wide;
    length combined $100.;
    combined=catx(', ', of state_:);
run;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_blank"&gt;https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192083"&gt;@radha009&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;i have data like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;request parent number&lt;/P&gt;
&lt;P&gt;123&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 234&amp;nbsp; &amp;nbsp; &amp;nbsp; 789&lt;/P&gt;
&lt;P&gt;123&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 234&amp;nbsp; &amp;nbsp; &amp;nbsp; 545&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want to merge like&lt;/P&gt;
&lt;P&gt;request parent number&lt;/P&gt;
&lt;P&gt;123 234 789/545&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how to code this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 20:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-rows-data/m-p/562108#M157431</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-28T20:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: merge two rows data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-two-rows-data/m-p/596902#M171935</link>
      <description>This was super useful, thank you!</description>
      <pubDate>Wed, 16 Oct 2019 14:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-two-rows-data/m-p/596902#M171935</guid>
      <dc:creator>LFern</dc:creator>
      <dc:date>2019-10-16T14:01:06Z</dc:date>
    </item>
  </channel>
</rss>

