<?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 do i take the date value of the next row record and deduct by 1 day? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962050#M375021</link>
    <description>&lt;PRE&gt;data have;
POLICE_ID = 'A'; POLICE_YEAR=2023; END_NUM = '0'; POLICE_EFF = '14Apr2023'd; POLICE_EXP='27Dec2023'd;
output;
POLICE_ID = 'A'; POLICE_YEAR=2023; END_NUM = '1'; POLICE_EFF = '28Dec2023'd; POLICE_EXP='31Dec2023'd;
output;
POLICE_ID = 'A'; POLICE_YEAR=2023; END_NUM = '2'; POLICE_EFF = '01Jan2024'd; POLICE_EXP='14Apr2024'd;
output;
format POLICE_EFF POLICE_EXP date9.;
run;

data want;
merge have have(keep=POLICE_ID POLICE_YEAR POLICE_EFF 
      rename=(POLICE_ID=_POLICE_ID POLICE_YEAR=_POLICE_YEAR POLICE_EFF=_POLICE_EFF ) firstobs=2);
if POLICE_ID=_POLICE_ID and POLICE_YEAR=_POLICE_YEAR then &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;POLICE_EXP&lt;/STRONG&gt;&lt;/FONT&gt;=_POLICE_EFF-1;
drop _:;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 18 Mar 2025 08:22:33 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2025-03-18T08:22:33Z</dc:date>
    <item>
      <title>How do i take the date value of the next row record and deduct by 1 day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962043#M375017</link>
      <description>&lt;P&gt;How do i take the date value of the next row record and deduct by 1 day?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have and wish to achieve is this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="StickyRoll_0-1742283792177.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105464i954027D10997A4CE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="StickyRoll_0-1742283792177.png" alt="StickyRoll_0-1742283792177.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Update 2: to better potray the data that I have and what i want to achieve&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="StickyRoll_0-1742285795133.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105467i599069BD4ACD94C6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="StickyRoll_0-1742285795133.png" alt="StickyRoll_0-1742285795133.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Notice the red value is supposed to be taken from the 2nd row and 3rd row, where the value is actually -1 of 28-Dec2023 and -1 of 1-jan-2024.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can i achieve this? It is possible to have more than 10 rows of such a record with unique "END_NUM" value for the same POLICE_ID and POLICE_YEAR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;POLICE_ID = A; POLICE_YEAR=2023; END_NUM = '0'; POLICE_EFF = '14Apr2023'd; POLICE_EXP='27Dec2023'd;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;POLICE_ID = A; POLICE_YEAR=2023; END_NUM = '1'; POLICE_EFF = '28Dec2023'd; POLICE_EXP='31Dec2023'd;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;POLICE_ID = A; POLICE_YEAR=2023; END_NUM = '2'; POLICE_EFF = '01Jan2024'd; POLICE_EXP='14Apr2024'd;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 08:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962043#M375017</guid>
      <dc:creator>StickyRoll</dc:creator>
      <dc:date>2025-03-18T08:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do i take the date value of the next row record and deduct by 1 day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962044#M375018</link>
      <description>&lt;P&gt;&lt;EM&gt;"It is possible to have more than 10 rows of such a record with unique "END_NUM" value for the same POLICE_ID and POLICE_YEAR."&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand this. Please provide sample data that resembles your request.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is&amp;nbsp;POLICE_EXP = 14-APR-24 in the second obs ?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 07:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962044#M375018</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2025-03-18T07:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do i take the date value of the next row record and deduct by 1 day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962046#M375019</link>
      <description>&lt;P&gt;So what kind of data do you have ? Do you have variable 'POLICE_EXP'&amp;nbsp; or just want to generate it?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
POLICE_ID = 'A'; POLICE_YEAR=2023; END_NUM = '0'; POLICE_EFF = '14Apr2023'd; POLICE_EXP='27Dec2023'd;
output;
POLICE_ID = 'A'; POLICE_YEAR=2023; END_NUM = '1'; POLICE_EFF = '28Dec2023'd; POLICE_EXP='14Apr2024'd;
format POLICE_EFF POLICE_EXP date9.;
output;
run;

data want;
merge have have(keep=POLICE_ID POLICE_YEAR POLICE_EFF 
      rename=(POLICE_ID=_POLICE_ID POLICE_YEAR=_POLICE_YEAR POLICE_EFF=_POLICE_EFF ) firstobs=2);
if POLICE_ID=_POLICE_ID and POLICE_YEAR=_POLICE_YEAR then want_POLICE_EXP=_POLICE_EFF-1;
format want_POLICE_EXP date9.;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1742285714926.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105465iBEC1467703323343/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1742285714926.png" alt="Ksharp_0-1742285714926.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 08:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962046#M375019</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-03-18T08:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do i take the date value of the next row record and deduct by 1 day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962049#M375020</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;I have updated my post by adding a new screenshot and revised my "data want" statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 08:18:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962049#M375020</guid>
      <dc:creator>StickyRoll</dc:creator>
      <dc:date>2025-03-18T08:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do i take the date value of the next row record and deduct by 1 day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962050#M375021</link>
      <description>&lt;PRE&gt;data have;
POLICE_ID = 'A'; POLICE_YEAR=2023; END_NUM = '0'; POLICE_EFF = '14Apr2023'd; POLICE_EXP='27Dec2023'd;
output;
POLICE_ID = 'A'; POLICE_YEAR=2023; END_NUM = '1'; POLICE_EFF = '28Dec2023'd; POLICE_EXP='31Dec2023'd;
output;
POLICE_ID = 'A'; POLICE_YEAR=2023; END_NUM = '2'; POLICE_EFF = '01Jan2024'd; POLICE_EXP='14Apr2024'd;
output;
format POLICE_EFF POLICE_EXP date9.;
run;

data want;
merge have have(keep=POLICE_ID POLICE_YEAR POLICE_EFF 
      rename=(POLICE_ID=_POLICE_ID POLICE_YEAR=_POLICE_YEAR POLICE_EFF=_POLICE_EFF ) firstobs=2);
if POLICE_ID=_POLICE_ID and POLICE_YEAR=_POLICE_YEAR then &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;POLICE_EXP&lt;/STRONG&gt;&lt;/FONT&gt;=_POLICE_EFF-1;
drop _:;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Mar 2025 08:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962050#M375021</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-03-18T08:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do i take the date value of the next row record and deduct by 1 day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962051#M375022</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&lt;BR /&gt;In your sample code, you hardcode firstobs=2. May I know if it is possible to make it dynamic instead? In my dataset, there are more than 100k of different POLICE_ID and may be even more later.</description>
      <pubDate>Tue, 18 Mar 2025 08:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962051#M375022</guid>
      <dc:creator>StickyRoll</dc:creator>
      <dc:date>2025-03-18T08:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do i take the date value of the next row record and deduct by 1 day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962052#M375023</link>
      <description>"make it dynamic "&lt;BR /&gt;Yes. My code is dynamic as long as your data has been sorted by POLICE_ID and POLICE_YEAR.</description>
      <pubDate>Tue, 18 Mar 2025 08:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962052#M375023</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-03-18T08:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do i take the date value of the next row record and deduct by 1 day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962054#M375025</link>
      <description>May i understand the purpose of having firstobs=2? I know it means the first observation should begin with row number 2 but what does it mean in this scenario?</description>
      <pubDate>Tue, 18 Mar 2025 09:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962054#M375025</guid>
      <dc:creator>StickyRoll</dc:creator>
      <dc:date>2025-03-18T09:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do i take the date value of the next row record and deduct by 1 day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962059#M375026</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/376676"&gt;@StickyRoll&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;May i understand the purpose of having firstobs=2? I know it means the first observation should begin with row number 2 but what does it mean in this scenario?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since this particular read starts at the second observation, it always provides a "look-ahead" into the next observation.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2025 10:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962059#M375026</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-03-18T10:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do i take the date value of the next row record and deduct by 1 day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962151#M375034</link>
      <description>&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;PRE&gt;id   x
1   1
1   2
2   2
2   3
2  4

if using my code with firstobs=2 option would look forward an obs as Kurt pointed out.
-----&amp;gt;
id  x  &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;_id  _x  &amp;lt;--- is from the second dataset with firstobs=2&lt;/STRONG&gt;&lt;/FONT&gt;
1  1    1    2
1  2    2    2
2   2   2    3
2   3   2    4
2   4   .    .&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Mar 2025 01:05:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-take-the-date-value-of-the-next-row-record-and-deduct/m-p/962151#M375034</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-03-19T01:05:21Z</dc:date>
    </item>
  </channel>
</rss>

