<?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: Trying to find difference between first and last date of same subject in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-find-difference-between-first-and-last-date-of-same/m-p/826193#M326336</link>
    <description>&lt;P&gt;Are these valid numeric SAS date/time values? What is the type of variable MED_ADMIN_DATE (numeric or character) according to PROC CONTENTS? What is the format of variable MED_ADMIN_DATE according to PROC CONTENTS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they are valid numeric SAS datetime value, then PROC SUMMARY gets the job done, it finds the difference in seconds, and then you can divide by 3600 to get hours.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
     class studynum;
     var MED_ADMIN_DATE;
     output out=want range=/autoname;
run;

data want; 
    set want;
    hours=MED_ADMIN_DATE_range/3600;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 29 Jul 2022 16:46:24 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-07-29T16:46:24Z</dc:date>
    <item>
      <title>Trying to find difference between first and last date of same subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-find-difference-between-first-and-last-date-of-same/m-p/826191#M326334</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Im trying to generate the difference between the first and last dates that a patient was on a certain medication in hours. These are listed in the same column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data have:&lt;/P&gt;&lt;P&gt;studynum &amp;nbsp; &amp;nbsp;med_admin_date&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10/26/20 8:00&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10/27/20 3:00&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10/28/20 8:00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want:&lt;/P&gt;&lt;P&gt;studynum &amp;nbsp; &amp;nbsp; difference&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 48&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 16:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-find-difference-between-first-and-last-date-of-same/m-p/826191#M326334</guid>
      <dc:creator>stancemcgraw</dc:creator>
      <dc:date>2022-07-29T16:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to find difference between first and last date of same subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-find-difference-between-first-and-last-date-of-same/m-p/826193#M326336</link>
      <description>&lt;P&gt;Are these valid numeric SAS date/time values? What is the type of variable MED_ADMIN_DATE (numeric or character) according to PROC CONTENTS? What is the format of variable MED_ADMIN_DATE according to PROC CONTENTS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they are valid numeric SAS datetime value, then PROC SUMMARY gets the job done, it finds the difference in seconds, and then you can divide by 3600 to get hours.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
     class studynum;
     var MED_ADMIN_DATE;
     output out=want range=/autoname;
run;

data want; 
    set want;
    hours=MED_ADMIN_DATE_range/3600;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jul 2022 16:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-find-difference-between-first-and-last-date-of-same/m-p/826193#M326336</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-29T16:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to find difference between first and last date of same subject</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-find-difference-between-first-and-last-date-of-same/m-p/826199#M326337</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    studynum,
    (max(med_admin_date) - min(med_admin_date)) / 3600 as difference
  from have
  group by studynum
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jul 2022 17:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-find-difference-between-first-and-last-date-of-same/m-p/826199#M326337</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-29T17:53:15Z</dc:date>
    </item>
  </channel>
</rss>

