<?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: Calculate the time difference between rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-the-time-difference-between-rows/m-p/738369#M230314</link>
    <description>&lt;P&gt;First read your visit dates as date values, not as character variables.&amp;nbsp; I.e. use the mmddyy8. informat to get sas to translate the 8 digits into the number of days after 01jan1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also assign a date format (such as date9.) so when SAS displays this value, you can see it as a calendar date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input Date_Visit mmddyy8. ID $ surgery $ BMI ;&lt;BR /&gt;format date_visit date9. ;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you want the dates closest to 6 mo prior and 6 mo after, or do you want (a) the most recent date at least 6 months prior, and (b) the earliest following date at least 6 months after?&lt;/P&gt;</description>
    <pubDate>Sun, 02 May 2021 03:19:05 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-05-02T03:19:05Z</dc:date>
    <item>
      <title>Calculate the time difference between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-the-time-difference-between-rows/m-p/738363#M230311</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to extract the BMI value before and after the surgery for following dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data diff_date;&lt;BR /&gt;input Date_Visit $ ID $ surgery $ BMI ;&lt;BR /&gt;cards;&lt;BR /&gt;07022002 1 0 40&lt;BR /&gt;11142002 1 0 35&lt;BR /&gt;05152003 1 1 35&lt;BR /&gt;11042003 1 0 25&lt;BR /&gt;05042004 2 0 50&lt;BR /&gt;11102004 2 0 53&lt;BR /&gt;05032005 2 1 45&lt;BR /&gt;05032006 2 0 32&lt;BR /&gt;05032007 2 0 25&lt;BR /&gt;11012005 3 0 30&lt;BR /&gt;06062006 3 1 25&lt;BR /&gt;07032006 3 0 18&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to extract the BMI value 6 months before the surgery, on the day of surgery, and 6 months after the surgery. I would really appreciate any thought. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;BR /&gt;Sandyzman1&lt;/P&gt;</description>
      <pubDate>Sun, 02 May 2021 01:47:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-the-time-difference-between-rows/m-p/738363#M230311</guid>
      <dc:creator>sandyzman1</dc:creator>
      <dc:date>2021-05-02T01:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the time difference between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-the-time-difference-between-rows/m-p/738369#M230314</link>
      <description>&lt;P&gt;First read your visit dates as date values, not as character variables.&amp;nbsp; I.e. use the mmddyy8. informat to get sas to translate the 8 digits into the number of days after 01jan1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also assign a date format (such as date9.) so when SAS displays this value, you can see it as a calendar date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input Date_Visit mmddyy8. ID $ surgery $ BMI ;&lt;BR /&gt;format date_visit date9. ;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you want the dates closest to 6 mo prior and 6 mo after, or do you want (a) the most recent date at least 6 months prior, and (b) the earliest following date at least 6 months after?&lt;/P&gt;</description>
      <pubDate>Sun, 02 May 2021 03:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-the-time-difference-between-rows/m-p/738369#M230314</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-05-02T03:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the time difference between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-the-time-difference-between-rows/m-p/738393#M230334</link>
      <description>&lt;P&gt;Hi mkeintz,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the suggestion. I'll make sure that I make those edits. For this analysis,&amp;nbsp;&lt;SPAN&gt;I want the dates closest to 6 mo prior and 6 mo after.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 May 2021 12:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-the-time-difference-between-rows/m-p/738393#M230334</guid>
      <dc:creator>sandyzman1</dc:creator>
      <dc:date>2021-05-02T12:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the time difference between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-the-time-difference-between-rows/m-p/738398#M230338</link>
      <description>&lt;P&gt;Plz post the output you want to see .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data diff_date;
input Date_Visit : mmddyy10. ID  surgery  BMI ;
format Date_Visit  mmddyy10.;
cards;
07022002 1 0 40
11142002 1 0 35
05152003 1 1 35
11042003 1 0 25
05042004 2 0 50
11102004 2 0 53
05032005 2 1 45
05032006 2 0 32
05032007 2 0 25
11012005 3 0 30
06062006 3 1 25
07032006 3 0 18
;
run;
data want;
 merge diff_date diff_date(keep=id date_visit surgery
rename=(date_visit=_date_visit surgery=_surgery) where=(_surgery=1));
by id;
if date_visit&amp;lt;intnx('month',_date_visit,-6,'s') or
   date_visit&amp;gt;intnx('month',_date_visit,6,'s') ;
drop _: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 May 2021 12:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-the-time-difference-between-rows/m-p/738398#M230338</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-05-02T12:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the time difference between rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-the-time-difference-between-rows/m-p/738425#M230353</link>
      <description>&lt;P&gt;Hi KSharp,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks. It worked. I wanted to get the date and BMI value 6 months before and after the surgery date to see how the bodyweight changed due to surgery. I added a few extra steps and got my answer. You are awesome. Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;BR /&gt;sandyzman1&lt;/P&gt;</description>
      <pubDate>Sun, 02 May 2021 19:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-the-time-difference-between-rows/m-p/738425#M230353</guid>
      <dc:creator>sandyzman1</dc:creator>
      <dc:date>2021-05-02T19:08:04Z</dc:date>
    </item>
  </channel>
</rss>

