<?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: comparing date field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/comparing-date-field/m-p/446964#M112220</link>
    <description>&lt;P&gt;1) It helps to provide data in the form of a data step. I did not see anything resembling an actual valid date (no year) so could not attempt to create data set to test code against.&lt;/P&gt;
&lt;P&gt;2) It would really help to show the actual result for your example data as I'm not sure what your actual result would be after that comment.&lt;/P&gt;
&lt;P&gt;3) if Bypass or FirstAcct play a role in this calculation you need to state it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Guessing at this point that you want to compare to the date associated with the first value of bypass within account.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by account bypass;  /* assumes the data is sorted by account and bypase*/
   retain firstdate .;
   if first.account then do;
      firstacct=0;
      firstdate=date;
   end;
   else firstacct= date-firstdate;
   drop firstdate;

run;&lt;/PRE&gt;</description>
    <pubDate>Mon, 19 Mar 2018 23:02:16 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-03-19T23:02:16Z</dc:date>
    <item>
      <title>comparing date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-date-field/m-p/446317#M111957</link>
      <description>&lt;P&gt;I could use some help comparing the date field in the below example.&amp;nbsp; I used first. to get the first record by account and bypass.&amp;nbsp; What i would like to do is compare the date field.&amp;nbsp; For example, for the account 55555 i'd like the date lag to show 0 for the first observation, and then 1 for the second observation since it is a day later than the first instance for that account number and bypass combination.&amp;nbsp;Observation 3 and 4 for account number 55555 should show a date lag of 0&amp;nbsp;for both as they share the same date.&amp;nbsp; &amp;nbsp;For account number 77777 id like the first and second record to show 0 as they are the same date, then the third record to show 2, and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&gt;&lt;TD&gt;3-Jan&lt;/TD&gt;&lt;TD&gt;2:10:00 AM&lt;/TD&gt;&lt;TD&gt;53&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;66666&lt;/TD&gt;&lt;TD&gt;1-Jan&lt;/TD&gt;&lt;TD&gt;2:10:00 AM&lt;/TD&gt;&lt;TD&gt;54&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;77777&lt;/TD&gt;&lt;TD&gt;1-Feb&lt;/TD&gt;&lt;TD&gt;3:00:00 AM&lt;/TD&gt;&lt;TD&gt;51&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;77777&lt;/TD&gt;&lt;TD&gt;1-Feb&lt;/TD&gt;&lt;TD&gt;3:15:00 AM&lt;/TD&gt;&lt;TD&gt;51&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;77777&lt;/TD&gt;&lt;TD&gt;3-Feb&lt;/TD&gt;&lt;TD&gt;3:30:00 AM&lt;/TD&gt;&lt;TD&gt;51&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;77777&lt;/TD&gt;&lt;TD&gt;5-Feb&lt;/TD&gt;&lt;TD&gt;3:45:00 AM&lt;/TD&gt;&lt;TD&gt;51&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 16 Mar 2018 19:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-date-field/m-p/446317#M111957</guid>
      <dc:creator>mac91red</dc:creator>
      <dc:date>2018-03-16T19:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: comparing date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-date-field/m-p/446336#M111966</link>
      <description>&lt;P&gt;If your date is actually a date value (very highly recommended) and a character then it is as simple as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by account;&amp;nbsp; /* assumes the data is sorted by account*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; difdate= dif(date);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if first.account then firstacct=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; else firstacct=difdate;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; drop difdate;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However I am afraid that you "date" may be character and is incomplete as I do not see any year component and there could be an issue the 1-Mar is 1Mar2017 or 1Mar2018 in consecutive records and should not be 0. Year also being an import consideration for 27-Feb to 1-Mar depending on leap years. If you can get a YEAR with that day-Month then create actual date values.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 20:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-date-field/m-p/446336#M111966</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-16T20:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: comparing date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-date-field/m-p/446434#M112001</link>
      <description>&lt;P&gt;Thanks for the reply - my date field is date9 but that is a numeric.&amp;nbsp; Does it have to be alpha?&amp;nbsp; I ran the code and the results weren't exactly what i expected.&amp;nbsp; For example the 77777 example the last observation has&amp;nbsp;a 4 day difference yet the output calculated only a 2 for difdate.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 12:30:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-date-field/m-p/446434#M112001</guid>
      <dc:creator>mac91red</dc:creator>
      <dc:date>2018-03-17T12:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: comparing date field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comparing-date-field/m-p/446964#M112220</link>
      <description>&lt;P&gt;1) It helps to provide data in the form of a data step. I did not see anything resembling an actual valid date (no year) so could not attempt to create data set to test code against.&lt;/P&gt;
&lt;P&gt;2) It would really help to show the actual result for your example data as I'm not sure what your actual result would be after that comment.&lt;/P&gt;
&lt;P&gt;3) if Bypass or FirstAcct play a role in this calculation you need to state it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Guessing at this point that you want to compare to the date associated with the first value of bypass within account.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by account bypass;  /* assumes the data is sorted by account and bypase*/
   retain firstdate .;
   if first.account then do;
      firstacct=0;
      firstdate=date;
   end;
   else firstacct= date-firstdate;
   drop firstdate;

run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Mar 2018 23:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comparing-date-field/m-p/446964#M112220</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-19T23:02:16Z</dc:date>
    </item>
  </channel>
</rss>

