<?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: How to calculate a duration from 2 dates? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426476#M281296</link>
    <description>&lt;P&gt;Take a look at the last two steps in&amp;nbsp; your program.&amp;nbsp; You are working with a data set named:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;saspms.datensatz_pms&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you changed the name to something else that doesn't exist:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sas.datensatz_pms&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Go back to the correct name, and we'll see what happens.&amp;nbsp; It might work, or the dates might need some conversion.&amp;nbsp; It's not possible to tell right now.&amp;nbsp; Excel handles dates differently than SAS.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jan 2018 14:57:22 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-01-10T14:57:22Z</dc:date>
    <item>
      <title>How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426398#M281292</link>
      <description>&lt;DIV class="lia-message-body lia-component-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Heyall!&lt;/P&gt;&lt;P&gt;Can anybody help me?&lt;/P&gt;&lt;P&gt;I have a big dataset with over 300 observations and I have the startingdate and the endingdate dd/mm/yyyy and I want to calculate the duration for each observation. Does anybody know how I can calulate the duration time in days from those two dates?&lt;/P&gt;&lt;P&gt;Thank you so much! Cheers, Mary&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 10 Jan 2018 12:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426398#M281292</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-01-10T12:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426409#M281293</link>
      <description>&lt;P&gt;If your dates are stored the way SAS expects dates to be stored, you can simply use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;duration = ending_date - starting_date;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on what you consider the duration to be you could conceivably add 1 to that number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your dates are character strings, you need them converted to the form that SAS expects to find for dates.&amp;nbsp; You could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;duration = input(ending_date, ddmmyy10.) - input(starting_date, ddmmyy10.);&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 12:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426409#M281293</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-10T12:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426458#M281294</link>
      <description>Thank you so much for your quick respond. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;Unfortunately its still not working. It tells me: ERROR: Libref SAS is not assigned.&lt;BR /&gt;So sorry to bother you, but I am totally new at this and have to learn it all by myself for my new job.&lt;BR /&gt;This is what I have so far:&lt;BR /&gt;&lt;BR /&gt;Libname saspms "C:\SAS_PMS";&lt;BR /&gt;&lt;BR /&gt;PROC IMPORT OUT= SASPMS.DATENSATZ_PMS&lt;BR /&gt;DATAFILE= "C:\SAS_PMS\Datensatz_PMS.xls"&lt;BR /&gt;DBMS=EXCELCS REPLACE;&lt;BR /&gt;RANGE="Sheet1$";&lt;BR /&gt;SCANTEXT=YES;&lt;BR /&gt;USEDATE=YES;&lt;BR /&gt;SCANTIME=YES;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;Proc print&lt;BR /&gt;data = saspms.datensatz_pms;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data saspms.datensatz_pms;&lt;BR /&gt;set saspms.datensatz_pms (keep=NIS_Nummer Art_der_Anzeige notificationdate Medicinalproduct StartingDate EndingDate Numberofpatients Numberofphysicians);&lt;BR /&gt;run;&lt;BR /&gt;Proc print&lt;BR /&gt;data = saspms.datensatz_pms;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data sas.datensatz_pms;&lt;BR /&gt;set sas.datensatz_pms;&lt;BR /&gt;duration = Endingdate - Startingdate;&lt;BR /&gt;run;&lt;BR /&gt;Thank you so much!&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Jan 2018 14:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426458#M281294</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-01-10T14:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426474#M281295</link>
      <description>&lt;P&gt;Provide some sample of your data. That makes it so much easier to help you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 14:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426474#M281295</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-01-10T14:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426476#M281296</link>
      <description>&lt;P&gt;Take a look at the last two steps in&amp;nbsp; your program.&amp;nbsp; You are working with a data set named:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;saspms.datensatz_pms&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you changed the name to something else that doesn't exist:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sas.datensatz_pms&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Go back to the correct name, and we'll see what happens.&amp;nbsp; It might work, or the dates might need some conversion.&amp;nbsp; It's not possible to tell right now.&amp;nbsp; Excel handles dates differently than SAS.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 14:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426476#M281296</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-10T14:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426477#M281297</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185853"&gt;@marysmith&lt;/a&gt; wrote:&lt;BR /&gt;Thank you so much for your quick respond. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;Unfortunately its still not working. It tells me: ERROR: Libref SAS is not assigned.&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Very simple. You assigned library "saspms" and used it (and I guess successfully), and then you suddenly use library "sas" in the last step.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 14:58:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426477#M281297</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-10T14:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426479#M281298</link>
      <description>Ah yeah! You`re right. Thank you so much!&lt;BR /&gt;But still unfortunately not working.&lt;BR /&gt;This ist the dataset, its an excel file&lt;BR /&gt;[cid:image001.png@01D38A2D.03B6CF30]&lt;BR /&gt;&lt;BR /&gt;##- Please type your rely above this line. No attachments. -##</description>
      <pubDate>Wed, 10 Jan 2018 15:07:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426479#M281298</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-01-10T15:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426485#M281299</link>
      <description>&lt;P&gt;Do never post data as pictures. Convert SAS datasets to data steps, using the macro from&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; or write the data step yourself. Post the data step code according to the advice in &lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Note: Excel files are not datasets and cannot be reasonably used to represent datasets; they have no defined vertical structure, so important attributes of SAS datasets are lost when data is exported.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 15:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426485#M281299</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-10T15:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426488#M281300</link>
      <description>&lt;P&gt;Your sample program includes a PROC PRINT toward the end.&amp;nbsp; Are you able to post a few lines from that, showing the Starting Date and the Ending Date?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would also be helpful if you could run a PROC CONTENTS on&amp;nbsp; your final data set, and post the information generated about those two variables.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 15:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426488#M281300</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-10T15:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426494#M281301</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="This is the Dataset in Excel" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17764i0A1250E4CE68290F/image-size/large?v=v2&amp;amp;px=999" role="button" title="sample.jpg" alt="This is the Dataset in Excel" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;This is the Dataset in Excel&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="proc_contents.JPG" style="width: 491px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17765i8151C6043AC513E5/image-size/large?v=v2&amp;amp;px=999" role="button" title="proc_contents.JPG" alt="proc_contents.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 15:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426494#M281301</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-01-10T15:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426499#M281302</link>
      <description>&lt;P&gt;Your date variables are character. You will need to convert them in data step before calculating the duration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sdate = input(startdate,ddmmyy10.);&lt;/P&gt;
&lt;P&gt;Edate= input(enddate,ddmmyy10.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;would create the SAS valued date variables and use Sdate and Edate for the duration.&lt;/P&gt;
&lt;P&gt;If you want to see the values of Sdate and Edate in a date format apply that such as&lt;/P&gt;
&lt;P&gt;Format sdate edate ddmmyy10.);&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 15:43:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426499#M281302</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-10T15:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426506#M281303</link>
      <description>&lt;P&gt;While converting the dates is a good idea, there is an alternative.&amp;nbsp; Instead, you can use the formula from my original post:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;duration = input(ending_date, ddmmyy10.) - input(starting_date, ddmmyy10.);&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 15:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426506#M281303</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-10T15:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a duration from 2 dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426508#M281304</link>
      <description>Thank you so much! It worked!&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Jan 2018 15:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-duration-from-2-dates/m-p/426508#M281304</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-01-10T15:51:39Z</dc:date>
    </item>
  </channel>
</rss>

