<?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: next date as end date by subject in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/next-date-as-end-date-by-subject/m-p/770577#M30899</link>
    <description>We then have to convert the character date to numeric date and follow the logic.</description>
    <pubDate>Mon, 27 Sep 2021 07:29:43 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2021-09-27T07:29:43Z</dc:date>
    <item>
      <title>next date as end date by subject</title>
      <link>https://communities.sas.com/t5/New-SAS-User/next-date-as-end-date-by-subject/m-p/770564#M30895</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a customer dataset with the dates. Each customer ordered multiple times. I want to create an end date based on the next order date.&lt;/P&gt;&lt;P&gt;For the last order of a customer, his end date will be the same as the order date.&lt;/P&gt;&lt;P&gt;If custome have only one order then&amp;nbsp;his end date will be the same as the order date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer_id&amp;nbsp; &amp;nbsp; &amp;nbsp;date&amp;nbsp;&lt;/P&gt;&lt;P&gt;111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02JAN2021&lt;/P&gt;&lt;P&gt;111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;05JAN2021&lt;/P&gt;&lt;P&gt;111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10JAN2021&amp;nbsp;&lt;/P&gt;&lt;P&gt;222&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 08JAN2021&lt;/P&gt;&lt;P&gt;333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12MAR2021&lt;/P&gt;&lt;P&gt;333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;18MAR2021&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output will be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer_id&amp;nbsp; &amp;nbsp; &amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end_date&lt;/P&gt;&lt;P&gt;111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02JAN2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05JAN2021&lt;/P&gt;&lt;P&gt;111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;05JAN2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10JAN2021&lt;/P&gt;&lt;P&gt;111&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10JAN2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10JAN2021&amp;nbsp;&lt;/P&gt;&lt;P&gt;222&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 08JAN2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08JAN2021&lt;/P&gt;&lt;P&gt;333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12MAR2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 18MAR2021&lt;/P&gt;&lt;P&gt;333&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;18MAR2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;18MAR2021&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Thank you"&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 04:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/next-date-as-end-date-by-subject/m-p/770564#M30895</guid>
      <dc:creator>sonicview</dc:creator>
      <dc:date>2021-09-27T04:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: next date as end date by subject</title>
      <link>https://communities.sas.com/t5/New-SAS-User/next-date-as-end-date-by-subject/m-p/770565#M30896</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Customer_id date :date9.;
cards;
111 02JAN2021
111 05JAN2021
111 10JAN2021 
222 08JAN2021
333 12MAR2021
333 18MAR2021
;

data want;
merge have have(keep=date rename=(date=date2) firstobs=2);
run;

proc sort data=want;
by Customer_id;
run;

data want2;
set want;
by Customer_id;
if last.Customer_id then date2=date;
format date: date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Sep 2021 04:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/next-date-as-end-date-by-subject/m-p/770565#M30896</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2021-09-27T04:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: next date as end date by subject</title>
      <link>https://communities.sas.com/t5/New-SAS-User/next-date-as-end-date-by-subject/m-p/770566#M30897</link>
      <description>&lt;P&gt;Another solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=sorted;
   by Customer_id descending date;
run;

data want;
   set sorted;
   by customer_id;
   
   format end_date date9.;
   
   last_date = lag(date);
   end_date = ifn(first.customer_id, date, last_date);
   
   drop last_date;
run;

proc sort data=want;
   by customer_id date;
run;
   &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Sep 2021 05:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/next-date-as-end-date-by-subject/m-p/770566#M30897</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-09-27T05:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: next date as end date by subject</title>
      <link>https://communities.sas.com/t5/New-SAS-User/next-date-as-end-date-by-subject/m-p/770568#M30898</link>
      <description>&lt;P&gt;Thank you! It can only wok if date is numeric, what is if date is in the char format?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Sep 2021 05:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/next-date-as-end-date-by-subject/m-p/770568#M30898</guid>
      <dc:creator>sonicview</dc:creator>
      <dc:date>2021-09-27T05:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: next date as end date by subject</title>
      <link>https://communities.sas.com/t5/New-SAS-User/next-date-as-end-date-by-subject/m-p/770577#M30899</link>
      <description>We then have to convert the character date to numeric date and follow the logic.</description>
      <pubDate>Mon, 27 Sep 2021 07:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/next-date-as-end-date-by-subject/m-p/770577#M30899</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2021-09-27T07:29:43Z</dc:date>
    </item>
  </channel>
</rss>

