<?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: Merging part of rows in dataset in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236341#M17047</link>
    <description>&lt;P&gt;Hi!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot for all the suggestions&amp;nbsp;for solutions, it is really helpfull. I will try them out and get back to you asap.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My biggest concern - and maybe I was not specific enough - is that it is only some of the data that needs to be mended. &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So my data set looks something&amp;nbsp;like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BM, &amp;nbsp;Asset_Class, Weight, Return&lt;/P&gt;
&lt;P&gt;23-11-2015, BM1, Stocks, 30%, 2,0%&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;24-11-2015, BM1, Stocks, 30%, 1,5%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;25-11-2015, BM1, Stocks, 30%, 1,2%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;23-11-2015, BM2, Stocks, 23%, 3,1%&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;24-11-2015, BM2, Stocks&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;26&lt;/SPAN&gt;&lt;SPAN&gt;%, 0,2%&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;25-11-2015, BM2, Stocks, 23%, 4,5%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;23-11-2015, BM1, &lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;Bonds&lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;15&lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;%, 3,1%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;24-11-2015, BM1, Bonds&lt;SPAN&gt;, 15&lt;/SPAN&gt;&lt;SPAN&gt;%, 0,2%&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;25-11-2015, BM1, Bonds, 15%, 4,5%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;23-11-2015, BM2, &lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;Bonds&lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;17&lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;%, 2,0%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;24-11-2015, BM2, Bonds, 18%, 1,5%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;25-11-2015, BM2, Bonds, 17%, 1,2%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So if the asset class equals stocks, then I would like to&amp;nbsp;mend the rows so I use everything but the return&amp;nbsp;from BM1, and only&amp;nbsp;the return coloum from BM2. Afterwards, every row with BM2 should be deleted from the data set.&amp;nbsp;For Bonds (and all other asset classes) I would just like to delete the rows containing BM2 (not mending the return column). &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot again!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Joe. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Nov 2015 08:56:34 GMT</pubDate>
    <dc:creator>JoeBill</dc:creator>
    <dc:date>2015-11-25T08:56:34Z</dc:date>
    <item>
      <title>Merging part of rows in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236209#M17041</link>
      <description>&lt;P&gt;&amp;nbsp;Hi there!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to combine two rows into one, taking only some information from both rows.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following hypothetically financial dataset:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date, BM, Asset_Class, Weight, Return&lt;/P&gt;
&lt;P&gt;24-11-2015, BM1, Stocks, 30%, 2%&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;24-11-2015, BM2, Stocks, 34%, 5%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create only one row, where I take the Date, Asset_Class and the weight from BM1 and the return variable from BM2. The new row will still have to be named named BM1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that possible?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best, Joe.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2015 15:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236209#M17041</guid>
      <dc:creator>JoeBill</dc:creator>
      <dc:date>2015-11-24T15:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Merging part of rows in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236218#M17042</link>
      <description>&lt;P&gt;Here's how you could do this in Base SAS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm=',';
input Date :ddmmyy10. BM $ Asset_Class $ Weight $ Return $;
format Date ddmmyyd10.;
cards;
24-11-2015, BM1, Stocks, 30%, 2%
24-11-2015, BM2, Stocks, 34%, 5%
;

proc sql;
create table want as
select *, (select Return from have where Date=a.Date &amp;amp; BM='BM2') as Return_BM2
from have a
where BM='BM1';
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes that variable DATE is the identifier to link&amp;nbsp;associated BM1 and BM2 records. I've read Weight and Return as character variables just for simplification. In practice, of course, these should be numeric variables (cf. PERCENT&lt;EM&gt;w.d&lt;/EM&gt; informat). Furthermore, I assume that Return_BM2 is to be displayed for comparison, not as a replacement of the original value of Return for BM1. If you want to replace the original Return value, you can simply delete the "&lt;FONT face="courier new,courier"&gt;_BM2&lt;/FONT&gt;" suffix from "&lt;FONT face="courier new,courier"&gt;Return_BM2&lt;/FONT&gt;" and add a &lt;FONT face="courier new,courier"&gt;(drop=Return)&lt;/FONT&gt; dataset option after the second "&lt;FONT face="courier new,courier"&gt;have&lt;/FONT&gt;" in the PROC SQL step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2015 16:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236218#M17042</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-24T16:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Merging part of rows in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236230#M17044</link>
      <description>&lt;P&gt;How reliable is your incoming data?&amp;nbsp; Do you always have raw data that includes the BM1 record followed by the matching BM2 record?&amp;nbsp; If that is a reliable pattern, you could code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;infile rawdata dlm=',' dsd truncover;&lt;/P&gt;
&lt;P&gt;length dummy $ 1;&lt;/P&gt;
&lt;P&gt;informat date ddmmyy10.;&lt;/P&gt;
&lt;P&gt;input date asset $ class $ weight $ / dummy dummy dummy dummy return $;&lt;/P&gt;
&lt;P&gt;format date ddmmyy10.;&lt;/P&gt;
&lt;P&gt;drop dummy;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2015 17:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236230#M17044</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-11-24T17:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Merging part of rows in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236287#M17045</link>
      <description>&lt;P&gt;With SAS datasets something like below could work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards dlm=',';
  input Date :ddmmyy10. BM $ Asset_Class $ Weight $ Return $;
  format Date ddmmyyd10.;
  cards;
24-11-2015, BM1, Stocks, 30%, 2%
24-11-2015, BM2, Stocks, 34%, 5%
;

proc sql;
  create table want as
    select 
      l.bm,l.date, l.asset_class, l.weight, r.return
    from  
      have(where=(bm='BM1')) l 
      left join 
      have(where=(bm='BM2')) r
    on l.date=r.date and l.asset_class=r.asset_class
    ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Nov 2015 22:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236287#M17045</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-24T22:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Merging part of rows in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236289#M17046</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's another method. It&amp;nbsp;assumes that&amp;nbsp;you always want the value from the next record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;input Date : ddmmyy10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;BM : $3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Asset_Class : $10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Weight : percent8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Return : percent8. ;&lt;/P&gt;
&lt;P&gt;format date date9.;&lt;/P&gt;
&lt;P&gt;datalines;&lt;BR /&gt;24-11-2015 BM1 Stocks 30% 2%&lt;/P&gt;
&lt;P&gt;24-11-2015 BM2 Stocks 34% 5% ;&lt;/P&gt;
&lt;P&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set have ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;if eof1=0 then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set have(firstobs=2 keep=return rename=(return=leadReturn)) end=eof1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;else leadReturn = .;&lt;BR /&gt;run;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take a look at this paper from&amp;nbsp;Mark Keintz -&amp;nbsp;&lt;A href="http://www.lexjansen.com/nesug/nesug13/113_Final_Paper.pdf" target="_blank"&gt;http://www.lexjansen.com/nesug/nesug13/113_Final_Paper.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- John&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2015 22:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236289#M17046</guid>
      <dc:creator>jnvickery</dc:creator>
      <dc:date>2015-11-24T22:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Merging part of rows in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236341#M17047</link>
      <description>&lt;P&gt;Hi!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot for all the suggestions&amp;nbsp;for solutions, it is really helpfull. I will try them out and get back to you asap.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My biggest concern - and maybe I was not specific enough - is that it is only some of the data that needs to be mended. &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So my data set looks something&amp;nbsp;like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date, &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BM, &amp;nbsp;Asset_Class, Weight, Return&lt;/P&gt;
&lt;P&gt;23-11-2015, BM1, Stocks, 30%, 2,0%&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;24-11-2015, BM1, Stocks, 30%, 1,5%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;25-11-2015, BM1, Stocks, 30%, 1,2%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;23-11-2015, BM2, Stocks, 23%, 3,1%&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;24-11-2015, BM2, Stocks&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;26&lt;/SPAN&gt;&lt;SPAN&gt;%, 0,2%&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;25-11-2015, BM2, Stocks, 23%, 4,5%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;23-11-2015, BM1, &lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;Bonds&lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;15&lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;%, 3,1%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;24-11-2015, BM1, Bonds&lt;SPAN&gt;, 15&lt;/SPAN&gt;&lt;SPAN&gt;%, 0,2%&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;25-11-2015, BM1, Bonds, 15%, 4,5%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;23-11-2015, BM2, &lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;Bonds&lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;17&lt;/SPAN&gt;&lt;SPAN style="line-height: 20px;"&gt;%, 2,0%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;24-11-2015, BM2, Bonds, 18%, 1,5%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;25-11-2015, BM2, Bonds, 17%, 1,2%&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So if the asset class equals stocks, then I would like to&amp;nbsp;mend the rows so I use everything but the return&amp;nbsp;from BM1, and only&amp;nbsp;the return coloum from BM2. Afterwards, every row with BM2 should be deleted from the data set.&amp;nbsp;For Bonds (and all other asset classes) I would just like to delete the rows containing BM2 (not mending the return column). &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot again!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Joe. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2015 08:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236341#M17047</guid>
      <dc:creator>JoeBill</dc:creator>
      <dc:date>2015-11-25T08:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Merging part of rows in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236374#M17048</link>
      <description>&lt;P&gt;Again, assuming that variable Date is the link between the obs. with BM='BM1' and the &lt;U&gt;unique&lt;/U&gt; corresponding obs. with BM='BM2', the following code should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm=',';
input Date :ddmmyy10. BM $ Asset_Class $ Weight $ Return $;
format Date ddmmyyd10.;
cards;
23-11-2015, BM1, Stocks, 30%, 2.0%
24-11-2015, BM1, Stocks, 30%, 1.5%
25-11-2015, BM1, Stocks, 30%, 1.2%
23-11-2015, BM2, Stocks, 23%, 3.1%
24-11-2015, BM2, Stocks, 26%, 0.2%
25-11-2015, BM2, Stocks, 23%, 4.5%
23-11-2015, BM1, Bonds, 15%, 3.1%
24-11-2015, BM1, Bonds, 15%, 0.2%
25-11-2015, BM1, Bonds, 15%, 4.5%
23-11-2015, BM2, Bonds, 17%, 2.0%
24-11-2015, BM2, Bonds, 18%, 1.5%
25-11-2015, BM2, Bonds, 17%, 1.2%
;

proc sql;
create table want(drop=Return rename=(NewReturn=Return)) as
select *, case when Asset_Class='Stocks'
               then (select Return from have where Asset_Class='Stocks' &amp;amp; Date=a.Date &amp;amp; BM='BM2')
               else Return
          end as NewReturn
from have a
where BM='BM1';
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Nov 2015 11:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merging-part-of-rows-in-dataset/m-p/236374#M17048</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-25T11:20:52Z</dc:date>
    </item>
  </channel>
</rss>

