<?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 combine rows into one in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/305362#M65136</link>
    <description>&lt;P&gt;Thanks PG, the do loop is pretty helpful!&lt;/P&gt;</description>
    <pubDate>Tue, 18 Oct 2016 13:27:55 GMT</pubDate>
    <dc:creator>Crubal</dc:creator>
    <dc:date>2016-10-18T13:27:55Z</dc:date>
    <item>
      <title>How to combine rows into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/304897#M64964</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have a data set (Table A) like below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Location_id |  Arrival_Date | Length_of_Stay | Demand   | 

------------+---------------+--------------- +----------+

   L_1      | 23-JUL-16     |  1             | 5        |

   L_1      | 23-JUL-16     |  2             | 7        |

   L_1      | 23-JUL-16     |  3             | 8        |

   L_1      | 23-JUL-16     |  4             | 3        |

   L_1      | 24-JUL-16     |  1             | 3        |

   L_1      | 24-JUL-16     |  2             | 2        |

   L_1      | 24-JUL-16     |  3             | 4        |

   L_1      | 25-JUL-16     |  1             | 5        | &lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;...........  ............    .............   .......&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to transfer to the following table:&lt;/SPAN&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;Location_id |  Stay_Date |  Demand   | 

 L_1        | 23-JUL-16  |  23       |

 L_1        | 24-JUL-16  |  27       |

 L_1        | 25-JUL-16  |  22       |

 L_1        | 26-JUL-16  |  7        |&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Where demand is measured as Stay_Date, which is calculated according to Arrival_Date and Length_of_Stay.&lt;/P&gt;&lt;P&gt;How can I make it in SAS? Thanks!&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Oct 2016 01:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/304897#M64964</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2016-10-16T01:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine rows into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/304898#M64965</link>
      <description>&lt;P&gt;There are many ways to get what you want like:&lt;/P&gt;
&lt;P&gt;1. Proc Means&lt;/P&gt;
&lt;P&gt;2. Proc SQL with a group by statement&lt;/P&gt;
&lt;P&gt;3. A SAS data step with a Retain for the sum, "by location_id arrival_date" and output "if last.arrival_date"&lt;/P&gt;
&lt;P&gt;4. ....&lt;/P&gt;</description>
      <pubDate>Sun, 16 Oct 2016 02:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/304898#M64965</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-16T02:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine rows into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/304900#M64967</link>
      <description>&lt;P&gt;Looks like you could do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table B as
select 
	location_id, 
	intnx("DAY", Arrival_date, Length_of_Stay-1) as Stay_date format=yymmdd10.,
	sum(Demand) as Demand
from A
group by location_id, calculated Stay_date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Oct 2016 03:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/304900#M64967</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-10-16T03:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine rows into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/305095#M65045</link>
      <description>&lt;P&gt;Hi PG,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used your code and generate the result where demand is measure by (Arrival_Date + Length_of_Stay -1)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I apologize that I did not explain clearly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example, date 23-Jul-16, demand is calculated by adding the first 4 rows. Since the first row spend 1 day, the second row spend 2 days, the third spend 3 days, and the fourth spend 4 days; and they are all staying at 23-Jul-16. And date 24-Jul-16 is calculated by adding rows 2,3,4 and rows 5,6,7 since they all stay at 24-Jul-16. Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 13:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/305095#M65045</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2016-10-17T13:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine rows into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/305279#M65099</link>
      <description>&lt;P&gt;One simple way to do this then is to expand the data to daily demand:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data temp;
set have;
do i = 1 to Length_of_stay;
    Stay_date = intnx("day", Arrival_date, i-1);
    output;
    end;
format stay_date yymmdd10.;
drop i;
run;

proc sql;
create table want as
select location_id, Stay_date, sum(demand) as Demand
from temp
group by location_id, stay_date;
select * from want;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Oct 2016 03:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/305279#M65099</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-10-18T03:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine rows into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/305362#M65136</link>
      <description>&lt;P&gt;Thanks PG, the do loop is pretty helpful!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2016 13:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-combine-rows-into-one/m-p/305362#M65136</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2016-10-18T13:27:55Z</dc:date>
    </item>
  </channel>
</rss>

