<?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 Calculate Date Difference between Activity Rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702868#M215299</link>
    <description>&lt;P&gt;I would like to calculate the date differences between activities for each ID, then tag those dates that happened within 30 days or less.&amp;nbsp; All advice is greatly appreciated. My first step would be to sort based on id and activity date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of my data:&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Activity Date&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1234&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200110&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1234&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200120&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1234&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200601&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;5678&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200110&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;5678&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200129&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;5678&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200220&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Tue, 01 Dec 2020 18:44:26 GMT</pubDate>
    <dc:creator>a_zacMD</dc:creator>
    <dc:date>2020-12-01T18:44:26Z</dc:date>
    <item>
      <title>Calculate Date Difference between Activity Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702868#M215299</link>
      <description>&lt;P&gt;I would like to calculate the date differences between activities for each ID, then tag those dates that happened within 30 days or less.&amp;nbsp; All advice is greatly appreciated. My first step would be to sort based on id and activity date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of my data:&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Activity Date&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1234&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200110&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1234&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200120&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1234&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200601&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;5678&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200110&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;5678&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200129&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;5678&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20200220&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 01 Dec 2020 18:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702868#M215299</guid>
      <dc:creator>a_zacMD</dc:creator>
      <dc:date>2020-12-01T18:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Date Difference between Activity Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702869#M215300</link>
      <description>&lt;P&gt;First, you need to treat Activity_Date as a numeric variable in SAS, and convert it to a true SAS date value (which is the number of days since 01JAN1960). This done in my INPUT statement using the informat YYMMDD8. Then the difference between dates is just a subtraction.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Activity_Date yymmdd8.;
cards;
1234 20200110
1234 20200120
1234 20200601
5678 20200110
5678 20200129
5678 20200220
;
data want;
    set have;
    by id;
    delta=activity_date-lag(activity_date);
    if first.id then delta=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Dec 2020 18:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702869#M215300</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-01T18:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Date Difference between Activity Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702870#M215301</link>
      <description>&lt;P&gt;Is that value an actual SAS date? Meaning a numeric value with a SAS date format applied such as YYMMDDN8. ?&lt;/P&gt;
&lt;P&gt;If not the first thing will be to create an actual date value so that the comparisons are easy.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 18:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702870#M215301</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-01T18:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Date Difference between Activity Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702876#M215303</link>
      <description>No, the date value is 20200801 = YYYYMMDD.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 01 Dec 2020 19:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702876#M215303</guid>
      <dc:creator>a_zacMD</dc:creator>
      <dc:date>2020-12-01T19:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Date Difference between Activity Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702877#M215304</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/334359"&gt;@a_zacMD&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;No, the date value is 20200801 = YYYYMMDD.&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So it has to be converted to a valid SAS date, which I showed how to do, and then the calculations are trivial.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 19:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702877#M215304</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-01T19:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Date Difference between Activity Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702884#M215306</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/334359"&gt;@a_zacMD&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;No, the date value is 20200801 = YYYYMMDD.&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Actually no it isn't. If it were a real date then adding 1 to the data would make 20201231 20200101. If you get 20201232 that is why it is not a date. SAS dates are numeric but use Formats to display the number as the desired date. That also allows all the SAS date related functions to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 20:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702884#M215306</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-01T20:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Date Difference between Activity Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702890#M215310</link>
      <description>thank you, this works great!!!</description>
      <pubDate>Tue, 01 Dec 2020 20:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702890#M215310</guid>
      <dc:creator>a_zacMD</dc:creator>
      <dc:date>2020-12-01T20:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Date Difference between Activity Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702891#M215311</link>
      <description>Thank you for posting this!!</description>
      <pubDate>Tue, 01 Dec 2020 20:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-Date-Difference-between-Activity-Rows/m-p/702891#M215311</guid>
      <dc:creator>a_zacMD</dc:creator>
      <dc:date>2020-12-01T20:28:46Z</dc:date>
    </item>
  </channel>
</rss>

