<?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 time differences (in minutes) between two different character variables? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-time-differences-in-minutes-between-two/m-p/303537#M60802</link>
    <description>&lt;P&gt;Thank you RW9 for your advice. However, since I am a very unexperienced SAS-user it is not completely clear to me how to interpret your syntax. Do I solve both problems directly while using this syntax? In addition, it is not clear to me what to fill&amp;nbsp;out at:&amp;nbsp;&lt;/P&gt;&lt;P&gt;time="10:15";&lt;BR /&gt;comp="14:";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand that my question consists of two problems. With respect to the first problem, I've tried the following syntax:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; test_3;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; test_3;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;hour2=input(hour,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;time5.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;wakeup2=input(wakeup,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;best.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;However, it led to the following error (see below) and no outputs were presented.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;NOTE: Invalid argument to function INPUT at line 1785 column 10.&lt;/P&gt;&lt;P&gt;NOTE: Invalid argument to function INPUT at line 1786 column 8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since this syntax did not work out well, I am also not able to come up with&amp;nbsp;a good&amp;nbsp;solution for the second problem (calculating the difference in time).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you mabye clarify the syntax in more detail? And, is it necessary that the two variables have the same format before being able to distract them from each other?&lt;/P&gt;</description>
    <pubDate>Mon, 10 Oct 2016 12:55:43 GMT</pubDate>
    <dc:creator>teuni</dc:creator>
    <dc:date>2016-10-10T12:55:43Z</dc:date>
    <item>
      <title>How to calculate time differences (in minutes) between two different character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-time-differences-in-minutes-between-two/m-p/303523#M60799</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to calculate time differences between hour-of-wake-up and&amp;nbsp;hours-of-eating (difference in minutes). For each participant I have the hour-of-wake up (e.g. 08:30; character variable $5.) and the hours at which foods are consumed (e.g. 09; character variable $3.). I've recently read a lot about&amp;nbsp;handling time in SAS, however I do not (yet) succeed to calculate the difference in time. I have mainly difficulties with the difference in format statement between the two variables. Can someone please explain me how to calculate the difference?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See attachment for example dataset and the output I would like to have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2016 10:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-time-differences-in-minutes-between-two/m-p/303523#M60799</guid>
      <dc:creator>teuni</dc:creator>
      <dc:date>2016-10-10T10:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time differences (in minutes) between two different character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-time-differences-in-minutes-between-two/m-p/303528#M60801</link>
      <description>&lt;P&gt;Sorry, attaching things as a document is not helpful. &amp;nbsp;Post test data as a datastep in the question, follow this post if you need help:&lt;/P&gt;
&lt;P&gt;&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for your problem how about:&lt;/P&gt;
&lt;PRE&gt;data want;
  time="10:15";
  comp="14:";
  diff= (input(substr(comp,1,2),best.)-hour(input(time,time5.))) * 60;
run;&lt;/PRE&gt;
&lt;P&gt;What your problem is is that you have two data problems. &amp;nbsp;First the complete time in text, it is always (unless for a report) to have time in a numeric time format, it will make everything far easier. &amp;nbsp;You can do this simply with input to time format (assuming full time). &amp;nbsp;The other one is more of an issue, why have a colon : if there is no time part, surely just keep it as numeric variable with number of hours. &amp;nbsp;10: makes no sense either way (unless for report). &amp;nbsp;The above takes hours away from each numeric variant and then multiply by 60 to get minutes. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To take away from this, keep data in an appropriate format.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2016 11:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-time-differences-in-minutes-between-two/m-p/303528#M60801</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-10T11:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time differences (in minutes) between two different character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-time-differences-in-minutes-between-two/m-p/303537#M60802</link>
      <description>&lt;P&gt;Thank you RW9 for your advice. However, since I am a very unexperienced SAS-user it is not completely clear to me how to interpret your syntax. Do I solve both problems directly while using this syntax? In addition, it is not clear to me what to fill&amp;nbsp;out at:&amp;nbsp;&lt;/P&gt;&lt;P&gt;time="10:15";&lt;BR /&gt;comp="14:";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand that my question consists of two problems. With respect to the first problem, I've tried the following syntax:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; test_3;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt; test_3;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;hour2=input(hour,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;time5.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;wakeup2=input(wakeup,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;best.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;However, it led to the following error (see below) and no outputs were presented.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;NOTE: Invalid argument to function INPUT at line 1785 column 10.&lt;/P&gt;&lt;P&gt;NOTE: Invalid argument to function INPUT at line 1786 column 8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since this syntax did not work out well, I am also not able to come up with&amp;nbsp;a good&amp;nbsp;solution for the second problem (calculating the difference in time).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you mabye clarify the syntax in more detail? And, is it necessary that the two variables have the same format before being able to distract them from each other?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2016 12:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-time-differences-in-minutes-between-two/m-p/303537#M60802</guid>
      <dc:creator>teuni</dc:creator>
      <dc:date>2016-10-10T12:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time differences (in minutes) between two different character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-time-differences-in-minutes-between-two/m-p/303539#M60803</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This part:&lt;/P&gt;
&lt;P&gt;In addition, it is not clear to me what to fill&amp;nbsp;out at:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;time="10:15";&lt;BR /&gt;comp="14:";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I put that in to simulate some test data as you didn't provide any in a usable format. &amp;nbsp;You would not need it in yours as you have the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, those notes are telling you that the data you have is not in the correct format for the input statement. &amp;nbsp;Either they are not right syntactically - i.e. not HH:MM for a time5., or not actually text at all. &amp;nbsp;I suspect looking at your code here:&lt;/P&gt;
&lt;PRE&gt;data test_3;
  set test_3;
  hour2=input(hour,time5.);    /* hour2 sound like the hour variable */
  wakeup2=input(wakeup,best.);   /* sounds like the time variable
run;

data test_3;
  set test_3;
  wakeup2=input(hour,time5.);    
  hour2=input(wakeup,best.);   
run;&lt;/PRE&gt;
&lt;P&gt;You have the variables the wrong way, i.e. your putting the hour variable into time5, and the time5 into best which doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now two things for future consideration. &amp;nbsp;Post test data - a datastep code which will generate the test data exactly as it is on your system. &amp;nbsp;This post explains;&lt;/P&gt;
&lt;P&gt;&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, for posting code, use the {i} or SAS run icon next to that to post code in - it retains the code formatting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2016 12:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-time-differences-in-minutes-between-two/m-p/303539#M60803</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-10T12:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate time differences (in minutes) between two different character variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-time-differences-in-minutes-between-two/m-p/303736#M60812</link>
      <description>&lt;P&gt;Thanks for the advice with respect to the analysis and the way of posting questions. Your suspections were correct. I had to switch the variables!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2016 09:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-time-differences-in-minutes-between-two/m-p/303736#M60812</guid>
      <dc:creator>teuni</dc:creator>
      <dc:date>2016-10-11T09:09:18Z</dc:date>
    </item>
  </channel>
</rss>

