<?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 Retain + Looping among multiple row records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217052#M307784</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm a student who is relatively new to SAS, and I haven't been able to solve this problem. Thank you in advance!! I have a dataset composed of a couple hundred thousand entries grouped by ID. I want to be able to use the retain function by id and for each of the entries.&lt;/P&gt;&lt;P&gt;An example of my dataset:&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 134px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" width="65"&gt;ID&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="69"&gt;DaystoEvent&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;301&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;499&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;B&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;B&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;250&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;C&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 377px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;What I would like in my dataset:&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 549px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" width="65"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="104"&gt;&lt;STRONG&gt;DaystoEvent&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="125"&gt;&lt;STRONG&gt;1_DaystoEvent&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="111"&gt;&lt;STRONG&gt;2_DaystoEvent&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="144"&gt;&lt;STRONG&gt;3_DaystoEvent&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;301&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;499&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;301&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;301&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;499&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;499&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;301&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;499&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;B&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;200&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;200&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;250&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;B&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;250&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;200&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;250&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;C&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, I'd like to use the "retain" function for the variable DaystoEvent for ALL the row records by "ID". I cannot create a simple array because each "ID" has a different number of entries, and my dataset is over 300,000 "Ids". I have figured out how to use the retain function for the first.ID (example below), but I cannot figure out how to do it for all records by ID. &lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 549px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" width="65"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;data work;&lt;/P&gt;&lt;P&gt;set work;&lt;/P&gt;&lt;P&gt;by I &lt;/P&gt;&lt;P&gt;Retain R_Daystoevent;&lt;/P&gt;&lt;P&gt;If first.ID then do;&lt;/P&gt;&lt;P&gt;R_Daystoevent=Daystoevent;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Louise&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Apr 2015 00:33:38 GMT</pubDate>
    <dc:creator>LLW</dc:creator>
    <dc:date>2015-04-07T00:33:38Z</dc:date>
    <item>
      <title>Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217052#M307784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm a student who is relatively new to SAS, and I haven't been able to solve this problem. Thank you in advance!! I have a dataset composed of a couple hundred thousand entries grouped by ID. I want to be able to use the retain function by id and for each of the entries.&lt;/P&gt;&lt;P&gt;An example of my dataset:&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 134px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" width="65"&gt;ID&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="69"&gt;DaystoEvent&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;301&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;499&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;B&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;B&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;250&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;C&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 377px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" style="border-top: none;"&gt;What I would like in my dataset:&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 549px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" width="65"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="104"&gt;&lt;STRONG&gt;DaystoEvent&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="125"&gt;&lt;STRONG&gt;1_DaystoEvent&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="111"&gt;&lt;STRONG&gt;2_DaystoEvent&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="144"&gt;&lt;STRONG&gt;3_DaystoEvent&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;301&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;499&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;301&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;301&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;499&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;499&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;301&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;499&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;B&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;200&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;200&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;250&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;B&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;250&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;200&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;250&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl64" height="15" style="border-top: none;"&gt;&lt;STRONG&gt;C&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl64" style="border-top: none; border-left: none;"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, I'd like to use the "retain" function for the variable DaystoEvent for ALL the row records by "ID". I cannot create a simple array because each "ID" has a different number of entries, and my dataset is over 300,000 "Ids". I have figured out how to use the retain function for the first.ID (example below), but I cannot figure out how to do it for all records by ID. &lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 549px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" height="15" width="65"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;data work;&lt;/P&gt;&lt;P&gt;set work;&lt;/P&gt;&lt;P&gt;by I &lt;/P&gt;&lt;P&gt;Retain R_Daystoevent;&lt;/P&gt;&lt;P&gt;If first.ID then do;&lt;/P&gt;&lt;P&gt;R_Daystoevent=Daystoevent;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Louise&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 00:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217052#M307784</guid>
      <dc:creator>LLW</dc:creator>
      <dc:date>2015-04-07T00:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217053#M307785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you absolutely need the second column?&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;If not proc transpose is a direct solution. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I also recommend naming your variables Days_to_event1 Days_to_event2. This way you can use the shortcut reference for variables if required.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;proc sort data=have; by ID daystoEvent; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;proc transpose data=have out=want prefix=Days_to_event;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;by ID;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;var DaysToEvent;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 00:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217053#M307785</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-04-07T00:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217054#M307786</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Similar to Fareeza's code, but producing the extra lines as well:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input ID $ DaystoEvent;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;A 100&lt;/P&gt;&lt;P&gt;A 301&lt;/P&gt;&lt;P&gt;A 499&lt;/P&gt;&lt;P&gt;B 200&lt;/P&gt;&lt;P&gt;B 250&lt;/P&gt;&lt;P&gt;C 100&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=work out=need(drop=_:) prefix=DaystoEvent;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=counter);&lt;/P&gt;&lt;P&gt;&amp;nbsp; length id $5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format daystoevent best12.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array days(3) DaystoEvent1-DaystoEvent3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; counter=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do while(counter le 3 and not missing(days(counter)));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Daystoevent=Days(counter);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; counter+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 00:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217054#M307786</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-04-07T00:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217055#M307787</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Fareeza,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much--really appreciate it. Unfortunately, I need to keep the second variable (DaysToEvent) because I need to take the difference between DaytoEvent_1- DaystoEvent, DaystoEvent_2-DaystoEvent, etc. Is there a way to keep the DaystoEvent column?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much,&lt;/P&gt;&lt;P&gt;Louise&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 01:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217055#M307787</guid>
      <dc:creator>LLW</dc:creator>
      <dc:date>2015-04-07T01:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217056#M307788</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Arthur, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much! Is there a way to make the array number for DaystoEvent a variable as opposed to just 3? This is because in my sample data, I know that the largest number of records per ID is 3. However because I have such a large dataset (300,000 IDs) with varied #'s of records per ID, I'm not sure sure how many variables of DaystoEvent I will need for the array in the actual dataset. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much,&lt;/P&gt;&lt;P&gt;Louise&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 01:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217056#M307788</guid>
      <dc:creator>LLW</dc:creator>
      <dc:date>2015-04-07T01:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217057#M307789</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input ID $ DaystoEvent;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;A 100&lt;/P&gt;&lt;P&gt;A 301&lt;/P&gt;&lt;P&gt;A 499&lt;/P&gt;&lt;P&gt;B 200&lt;/P&gt;&lt;P&gt;B 250&lt;/P&gt;&lt;P&gt;C 100&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=work out=need(drop=_:) prefix=DaystoEvent_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=counter);&lt;/P&gt;&lt;P&gt;&amp;nbsp; length id $5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format daystoevent best12.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array days(*) DaystoEvent_:;&lt;/P&gt;&lt;P&gt;&amp;nbsp; counter=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do while(counter le dim(days) and not missing(days(counter)));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Daystoevent=Days(counter);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; counter+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 01:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217057#M307789</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2015-04-07T01:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217058#M307790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;I think this is the same: DaysToEvent(n)-daystoevent(1) be the same&amp;nbsp; as DaysToEvent(n)-DaysToEvent?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;*Get max count &lt;/SPAN&gt;of&lt;SPAN style="font-size: 10pt;"&gt; records;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;sql&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;select&lt;/SPAN&gt; max(count) into :max_count &lt;SPAN style="color: #0433ff;"&gt;from&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;(&lt;SPAN style="color: #0433ff;"&gt;select&lt;/SPAN&gt; count(ID) &lt;SPAN style="color: #0433ff;"&gt;as&lt;/SPAN&gt; count &lt;SPAN style="color: #0433ff;"&gt;from&lt;/SPAN&gt; Have&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New';"&gt;&lt;SPAN style="color: #0433ff;"&gt;group&lt;/SPAN&gt; &lt;SPAN style="color: #0433ff;"&gt;by&lt;/SPAN&gt; ID);&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 10px; font-family: 'Courier New'; color: #011993;"&gt;&lt;SPAN style="color: #000000;"&gt;*Transpose;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;proc sort data=have; by ID daystoEvent; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;proc transpose data=have out=want prefix=Days_to_event;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;by ID;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;var DaysToEvent;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;*calculate differences;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;data want2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;set want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;array days2(*) days_to_event1-days_to_event&amp;amp;max_count;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;array diff(*) days_diff1-days_diff&amp;amp;max_count;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;do i=1 to dim(days2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;diff(i)=days2(i)-days2(1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 01:31:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217058#M307790</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-04-07T01:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217059#M307791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data work;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input ID $ DaystoEvent;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A 100&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A 301&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A 499&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B 200&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;B 250&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C 100&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql; /* copied from Reeza's*/&lt;BR /&gt; select max(count) into :max_count separated by ' ' from &lt;BR /&gt; (select count(ID) as count from work&lt;BR /&gt;&amp;nbsp; group by ID);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; data want;&lt;BR /&gt; do _n_=1 by 1 until(last.id);&lt;BR /&gt;&amp;nbsp; set work;&lt;BR /&gt;&amp;nbsp; by id;&lt;BR /&gt;&amp;nbsp; array days(*) Daystoevent1-Daystoevent&amp;amp;max_count;&lt;BR /&gt;&amp;nbsp; days(_n_)=DaystoEvent;&lt;BR /&gt; end;&lt;/P&gt;&lt;P&gt; do until(last.id);&lt;BR /&gt;&amp;nbsp; set work;&lt;BR /&gt;&amp;nbsp; by id;&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;&lt;P&gt;L&amp;amp;T Infotech&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 04:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217059#M307791</guid>
      <dc:creator>naveen_srini</dc:creator>
      <dc:date>2015-04-07T04:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217060#M307792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, still not clear why you need a transposed dataset.&amp;nbsp; As you state, there could be many per id, so you could end up with thousands of columns.&lt;/P&gt;&lt;P&gt;Why not just assign a number in the dataset, then using merging to get days from:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input ID $ DaystoEvent;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;A 100&lt;/P&gt;&lt;P&gt;A 301&lt;/P&gt;&lt;P&gt;A 499&lt;/P&gt;&lt;P&gt;B 200&lt;/P&gt;&lt;P&gt;B 250&lt;/P&gt;&lt;P&gt;C 100&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain no;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 or first.id then no=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else no=no+1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table WANT as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select&amp;nbsp; A.ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.NO,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.DAYSTOEVENT,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.DAYSTOEVENT - B.DAYSTOEVENT as RES&lt;/P&gt;&lt;P&gt;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp; WORK.HAVE A&lt;/P&gt;&lt;P&gt;&amp;nbsp; left join (select * from WORK.HAVE where NO=1) B&lt;/P&gt;&lt;P&gt;&amp;nbsp; on&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.ID=B.ID&lt;/P&gt;&lt;P&gt;&amp;nbsp; order by A.ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.NO;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 08:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217060#M307792</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-04-07T08:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217061#M307793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did I miss something ? Why not just a simple MERGE ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;
data have;
&amp;nbsp; input ID $ DaystoEvent;
&amp;nbsp; cards;
A 100
A 301
A 499
B 200
B 250
C 100
;
run;

proc transpose data=have out=temp(drop=_name_) prefix=Days_to_event;
by ID;
var DaysToEvent;
run;
data want;
 merge have temp;
 by id;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 13:06:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217061#M307793</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-04-07T13:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217062#M307794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;At least 90% of the time, this sort of restructuring of the data is not necessary.&amp;nbsp; If you were to post a different question, describing the analysis you would like to perform, you would likely receive many answers that utilize your original structure to the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 13:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217062#M307794</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-04-07T13:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: Retain + Looping among multiple row records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217063#M307795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This was my first time posting a question, and thank you to everyone for your help. I have received so many different ways of getting what I wanted. Part of the reason that I wanted all the "DaysToEvents" in columns was because I need to find the difference between all combinations of the difference of DaystoEvents by ID, and I thought that the best way to take differences was to use columns. But Astounding is right, I will have very many columns of new DaystoEvents (233 to be exact!). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will think about how to move forward with the analysis that I want using this data structure, given the large columns.&lt;/P&gt;&lt;P&gt;Thank you to everyone!&lt;/P&gt;&lt;P&gt;Louise&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Apr 2015 14:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Looping-among-multiple-row-records/m-p/217063#M307795</guid>
      <dc:creator>LLW</dc:creator>
      <dc:date>2015-04-07T14:35:55Z</dc:date>
    </item>
  </channel>
</rss>

