<?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: Data Rollup in SAS Software for Learning Community</title>
    <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921605#M1815</link>
    <description>&lt;P&gt;If you are positive you always have 2 and only 2 observations then something like this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input id name :$20. age ;
cards;
1 Bruce 30
1 Wayne 30
2 Dick  18
2 Grayson 18
3 Alfred 50
3 Pennyworth 50
;

data want;
  set have(in=in1 rename=(name=firstname));
  by id;
  set have(in=in2 rename=(name=lastname) firstobs=2);
  if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    id    firstname    age    lastname

 1      1     Bruce        30    Wayne
 2      2     Dick         18    Grayson
 3      3     Alfred       50    Pennyworth
&lt;/PRE&gt;
&lt;P&gt;If you might have 1,2 or more then perhaps something like this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until(last.id);
    set have;
    by id;
    length fullname $50;
    fullname=catx(' ',fullname,name);
  end;
  drop name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    id    age    fullname

 1      1     30    Bruce Wayne
 2      2     18    Dick Grayson
 3      3     50    Alfred Pennyworth


&lt;/PRE&gt;</description>
    <pubDate>Sat, 23 Mar 2024 22:31:59 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-03-23T22:31:59Z</dc:date>
    <item>
      <title>Data Rollup</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921588#M1808</link>
      <description>&lt;P&gt;I want to roll-up data where two entries should be converted into one.&amp;nbsp;So can anyone please suggest a code for the same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following image shows the example of data I have:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Data I have" style="width: 149px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94898iA332ABD9516758D5/image-size/large?v=v2&amp;amp;px=999" role="button" title="Data rollup.JPG" alt="Data I have" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Data I have&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following image shows the result I want:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Result I want" style="width: 193px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94899i191FA1862147E42B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Data rollup1.JPG" alt="Result I want" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Result I want&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2024 13:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921588#M1808</guid>
      <dc:creator>ketan_korde</dc:creator>
      <dc:date>2024-03-23T13:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: Data Rollup</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921589#M1809</link>
      <description>Does your data not have any other columns such as an ID ?&lt;BR /&gt;&lt;BR /&gt;With only two records it’s difficult to say which approach would work best for your data.&lt;BR /&gt;&lt;BR /&gt;For instance, are there always two rows?&lt;BR /&gt;1 for the name and another for last name?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 23 Mar 2024 15:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921589#M1809</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-23T15:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Data Rollup</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921590#M1810</link>
      <description>Yes. There is Id variable and yes there is always two rows.</description>
      <pubDate>Sat, 23 Mar 2024 15:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921590#M1810</guid>
      <dc:creator>ketan_korde</dc:creator>
      <dc:date>2024-03-23T15:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Data Rollup</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921591#M1811</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;data have;
	infile datalines dlm=',';
	input id name $ age;
datalines;
0,Eric,30
0,Bishoff,30
1,Dave,60
1,Batista,60
;
run;

data want;
	length name firstname $200;
	set have;
	by id;
	retain firstname '';
	if first.id then firstname=name;
	else if last.id then do;
		name = catx(' ', firstname, name);
		output;
	end;
	drop firstname;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;can you try this?&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2024 15:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921591#M1811</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-23T15:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Data Rollup</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921605#M1815</link>
      <description>&lt;P&gt;If you are positive you always have 2 and only 2 observations then something like this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input id name :$20. age ;
cards;
1 Bruce 30
1 Wayne 30
2 Dick  18
2 Grayson 18
3 Alfred 50
3 Pennyworth 50
;

data want;
  set have(in=in1 rename=(name=firstname));
  by id;
  set have(in=in2 rename=(name=lastname) firstobs=2);
  if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    id    firstname    age    lastname

 1      1     Bruce        30    Wayne
 2      2     Dick         18    Grayson
 3      3     Alfred       50    Pennyworth
&lt;/PRE&gt;
&lt;P&gt;If you might have 1,2 or more then perhaps something like this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until(last.id);
    set have;
    by id;
    length fullname $50;
    fullname=catx(' ',fullname,name);
  end;
  drop name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    id    age    fullname

 1      1     30    Bruce Wayne
 2      2     18    Dick Grayson
 3      3     50    Alfred Pennyworth


&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Mar 2024 22:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921605#M1815</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-23T22:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: Data Rollup</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921607#M1816</link>
      <description>Will AGE always be consistent, or could the same ID have two different ages?</description>
      <pubDate>Sat, 23 Mar 2024 23:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921607#M1816</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-03-23T23:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Data Rollup</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921609#M1817</link>
      <description>&lt;P&gt;If you &lt;EM&gt;&lt;STRONG&gt;always&lt;/STRONG&gt;&lt;/EM&gt; have exactly 2, with first name always preceding last name:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge have (keep=id name rename=(name=firstname))
        have (firstobs=2   rename=(name=lastname));
  if mod(_n_,2)=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Mar 2024 02:10:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921609#M1817</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-03-24T02:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: Data Rollup</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921615#M1818</link>
      <description>Yes, Age will be consistent.</description>
      <pubDate>Sun, 24 Mar 2024 05:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921615#M1818</guid>
      <dc:creator>ketan_korde</dc:creator>
      <dc:date>2024-03-24T05:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Data Rollup</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921616#M1819</link>
      <description>This is working. Thanks</description>
      <pubDate>Sun, 24 Mar 2024 05:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921616#M1819</guid>
      <dc:creator>ketan_korde</dc:creator>
      <dc:date>2024-03-24T05:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Data Rollup</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921617#M1820</link>
      <description>Hi Tom, Thank you for the solution its working.</description>
      <pubDate>Sun, 24 Mar 2024 05:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921617#M1820</guid>
      <dc:creator>ketan_korde</dc:creator>
      <dc:date>2024-03-24T05:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Data Rollup</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921618#M1821</link>
      <description>Hi mkeintz, Thank you for the solution.</description>
      <pubDate>Sun, 24 Mar 2024 05:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/Data-Rollup/m-p/921618#M1821</guid>
      <dc:creator>ketan_korde</dc:creator>
      <dc:date>2024-03-24T05:28:00Z</dc:date>
    </item>
  </channel>
</rss>

