<?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 Difference in terms of days between dates in same column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/340864#M77956</link>
    <description>&lt;P&gt;Hi I am trying to find out difference between dates as per Name.&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;INPUT NAME $ DOB;&lt;BR /&gt;INFORMAT DOB DATE9.;&lt;BR /&gt;FORMAT DOB DATE9.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;NITISH 10MAR2016&lt;BR /&gt;PRIYA 10DEC2016&lt;BR /&gt;PRIYA 01JAN2016&lt;/P&gt;&lt;P&gt;SAKSHI 20DEC2016&lt;/P&gt;&lt;P&gt;SAKSHI 20APR2016&lt;BR /&gt;SAKSHI 02JAN2016&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;So output will be like&lt;/P&gt;&lt;P&gt;NAME &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DIFF&lt;BR /&gt;NITISH &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(&lt;SPAN&gt;10MAR2016-10MAR2016) i.e. 0 days&lt;/SPAN&gt;&lt;BR /&gt;PRIYA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (10DEC2016-10DEC2016)&lt;BR /&gt;SAKSHI &amp;nbsp; &amp;nbsp; &amp;nbsp; (20DEC2016-20APR2016)&lt;BR /&gt;SAKSHI &amp;nbsp; &amp;nbsp; &amp;nbsp; (20DEC2016-02JAN2016)&lt;BR /&gt;SAKSHI &amp;nbsp; &amp;nbsp; &amp;nbsp; (20APR2016-02JAN2016)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me to reach to solution. Itried using proc sort and appling lag in my dataset but was not able to achieve the results&lt;/P&gt;</description>
    <pubDate>Tue, 14 Mar 2017 17:21:43 GMT</pubDate>
    <dc:creator>Nitish1003</dc:creator>
    <dc:date>2017-03-14T17:21:43Z</dc:date>
    <item>
      <title>Difference in terms of days between dates in same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/340864#M77956</link>
      <description>&lt;P&gt;Hi I am trying to find out difference between dates as per Name.&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;INPUT NAME $ DOB;&lt;BR /&gt;INFORMAT DOB DATE9.;&lt;BR /&gt;FORMAT DOB DATE9.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;NITISH 10MAR2016&lt;BR /&gt;PRIYA 10DEC2016&lt;BR /&gt;PRIYA 01JAN2016&lt;/P&gt;&lt;P&gt;SAKSHI 20DEC2016&lt;/P&gt;&lt;P&gt;SAKSHI 20APR2016&lt;BR /&gt;SAKSHI 02JAN2016&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;So output will be like&lt;/P&gt;&lt;P&gt;NAME &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DIFF&lt;BR /&gt;NITISH &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(&lt;SPAN&gt;10MAR2016-10MAR2016) i.e. 0 days&lt;/SPAN&gt;&lt;BR /&gt;PRIYA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (10DEC2016-10DEC2016)&lt;BR /&gt;SAKSHI &amp;nbsp; &amp;nbsp; &amp;nbsp; (20DEC2016-20APR2016)&lt;BR /&gt;SAKSHI &amp;nbsp; &amp;nbsp; &amp;nbsp; (20DEC2016-02JAN2016)&lt;BR /&gt;SAKSHI &amp;nbsp; &amp;nbsp; &amp;nbsp; (20APR2016-02JAN2016)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me to reach to solution. Itried using proc sort and appling lag in my dataset but was not able to achieve the results&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 17:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/340864#M77956</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2017-03-14T17:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in terms of days between dates in same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/340899#M77963</link>
      <description>&lt;P&gt;I don't understand your desired results.&amp;nbsp;Priya, for example, has "&lt;SPAN&gt;PRIYA (10DEC2016-10DEC2016)" but I don't see any result for her second row of data with 01JAN2016.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Shouldn't there be a result for PRIYA 10DEC2016 and 01JAN2016 with a difference of 344 days?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you can tighten up what you expect to see, it will be easier to come up with a solution.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My apologies if I simply don't understand.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Collin&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 18:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/340899#M77963</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-03-14T18:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in terms of days between dates in same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/340909#M77964</link>
      <description>&lt;P&gt;I think you're looking for something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;                  
  create table want as    
    select a.*, count(a.name) as count, b.dob as dob2,
           abs(dob2-a.dob) as diff           
      from test a join test b
        on a.name eq b.name
          group by a.name
            order by a.id
  ;              
quit; 
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 18:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/340909#M77964</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-14T18:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in terms of days between dates in same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341027#M77981</link>
      <description>&lt;P&gt;Sorry for the typo the output will be like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;NAME &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DIFF&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NITISH &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(&lt;/SPAN&gt;&lt;SPAN&gt;10MAR2016-10MAR2016) i.e. 0 days&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PRIYA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (10DEC2016-01JAN016)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SAKSHI &amp;nbsp; &amp;nbsp; &amp;nbsp; (20DEC2016-20APR2016)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SAKSHI &amp;nbsp; &amp;nbsp; &amp;nbsp; (20DEC2016-02JAN2016)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SAKSHI &amp;nbsp; &amp;nbsp; &amp;nbsp; (20APR2016-02JAN2016)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This would ne my deisre reult. Please Collin if you check it and let me know how to solve this problem.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Nitish&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 01:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341027#M77981</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2017-03-15T01:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in terms of days between dates in same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341035#M77984</link>
      <description>&lt;P&gt;You want to calculate the maximum date range of DOB for each name, and then assign that diff to every record in the data set.&amp;nbsp; If your data test is grouped (but not neccessarily in ascending or descending order) by name, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want (drop=mindob maxdob);
 do until (last.name);
   set test;
   by name notsorted;
   mindob=min(mindob,dob);
   maxdob=max(maxdob,dob);
 end;
 diff=maxdob-mindob;
 do until (last.name);
   set test;
   by name notsorted;
   output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Read in all the records for a single id, while updating MINDOB and MAXDOB for that ID&lt;/LI&gt;
&lt;LI&gt;Calculates DIFF&lt;/LI&gt;
&lt;LI&gt;Re-reads all the records for the same id, and outputs the record, now with correct DIFF&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 15 Mar 2017 02:10:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341035#M77984</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-15T02:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in terms of days between dates in same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341201#M78063</link>
      <description>&lt;P&gt;Hi Sir&lt;/P&gt;&lt;P&gt;Your solution allmost worked for me but facing one issue.I am getting duplicate data i.e.&lt;/P&gt;&lt;P&gt;Example for Priya&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name &amp;nbsp; &amp;nbsp; DOB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; count &amp;nbsp; &amp;nbsp; DOB2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;diff&lt;/P&gt;&lt;P&gt;Priya &amp;nbsp; &amp;nbsp;01JAN2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;10DEC2016 &amp;nbsp; &amp;nbsp;344&lt;/P&gt;&lt;P&gt;Priya &amp;nbsp; &amp;nbsp;10DEC2016 &amp;nbsp; &amp;nbsp; &amp;nbsp;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JAN2016 &amp;nbsp; &amp;nbsp; 344&lt;/P&gt;&lt;P&gt;Is there way to Over come this because i want only one row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 14:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341201#M78063</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2017-03-15T14:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in terms of days between dates in same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341221#M78071</link>
      <description>&lt;P&gt;Is the following what you want?:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
  INPUT NAME $ DOB;
  INFORMAT DOB DATE9.;
  FORMAT DOB DATE9.;
  id=_n_;
  DATALINES;
NITISH 10MAR2016
PRIYA 10DEC2016
PRIYA 01JAN2016
SAKSHI 20DEC2016
SAKSHI 20APR2016
SAKSHI 02JAN2016
;
proc sql;                  
  create table want as    
    select a.*, count(a.name) as count, b.dob as dob2,
           abs(dob2-a.dob) as diff           
      from test a join test b
        on a.name eq b.name
          group by a.name
            having a.id le b.id
              order by a.id
  ;              
quit;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 15:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341221#M78071</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-15T15:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in terms of days between dates in same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341249#M78080</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/87248"&gt;@Nitish1003&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason you saw duplicates in the output of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;'s first response is because that is how you displayed the desired output in your initial post.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2017 16:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341249#M78080</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-15T16:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Difference in terms of days between dates in same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341270#M78086</link>
      <description>Thanks sir for the help. I missed the Id part in first solution.Thanks a lot for help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 15 Mar 2017 17:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-in-terms-of-days-between-dates-in-same-column/m-p/341270#M78086</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2017-03-15T17:32:42Z</dc:date>
    </item>
  </channel>
</rss>

