<?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: SAS Time format in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Time-format/m-p/47904#M12911</link>
    <description>Hi:&lt;BR /&gt;
  If you have a character variable and you want to convert it to a numeric value for time (number of seconds since midnight), then you must use the INPUT function to turn your character value into a numeric variable.&lt;BR /&gt;
 &lt;BR /&gt;
  For example, let's say that you have a variable called CHARTIME whose value is "06:51:23" and you want to convert that number to a SAS time value. Then your INPUT function would look something like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
   sastime = input(chartime,time8.);&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                    &lt;BR /&gt;
The INPUT function, converts a CHARACTER variable to a NUMERIC variable, using the INFORMAT that you specify as the second argument to the function. Now that SASTIME is internally stored as a number of seconds since midnight, you can now do a comparison. Assuming you mean you want to set a flag based on the time being before 3:00 PM (15:00:00), then your IF statement might look like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
  if sastime le "15:00:00"t then newvar = 1;&lt;BR /&gt;
  else newvar = 0;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                               &lt;BR /&gt;
The documentation on SAS date and date/time and time variables is quite good and there are a lot of good examples of using the INPUT function in the documentation. The specification "15:00:00"t in the IF statement is called a "time constant" and, again, looking in the documentation on the use of SAS date, time and datetime constants will help you understand more about the task you want/need to do.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Tue, 13 Jul 2010 04:21:27 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2010-07-13T04:21:27Z</dc:date>
    <item>
      <title>SAS Time format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Time-format/m-p/47903#M12910</link>
      <description>hello,&lt;BR /&gt;
&lt;BR /&gt;
I am working with SAS tables that currently have time values listed in character form (ex:  06:51:23, in hours minutes seconds). I need to convert this to SAS time (or any other SAS format) so as to make a new variable, say, before_3 which will be a dummy varaible taking value 1 if the time is before 4 p.m. and 0 otherwise.&lt;BR /&gt;
&lt;BR /&gt;
any suggestions?&lt;BR /&gt;
&lt;BR /&gt;
Kind Regards,&lt;BR /&gt;
Mark</description>
      <pubDate>Tue, 13 Jul 2010 03:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Time-format/m-p/47903#M12910</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-07-13T03:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Time format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-Time-format/m-p/47904#M12911</link>
      <description>Hi:&lt;BR /&gt;
  If you have a character variable and you want to convert it to a numeric value for time (number of seconds since midnight), then you must use the INPUT function to turn your character value into a numeric variable.&lt;BR /&gt;
 &lt;BR /&gt;
  For example, let's say that you have a variable called CHARTIME whose value is "06:51:23" and you want to convert that number to a SAS time value. Then your INPUT function would look something like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
   sastime = input(chartime,time8.);&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                    &lt;BR /&gt;
The INPUT function, converts a CHARACTER variable to a NUMERIC variable, using the INFORMAT that you specify as the second argument to the function. Now that SASTIME is internally stored as a number of seconds since midnight, you can now do a comparison. Assuming you mean you want to set a flag based on the time being before 3:00 PM (15:00:00), then your IF statement might look like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
  if sastime le "15:00:00"t then newvar = 1;&lt;BR /&gt;
  else newvar = 0;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                               &lt;BR /&gt;
The documentation on SAS date and date/time and time variables is quite good and there are a lot of good examples of using the INPUT function in the documentation. The specification "15:00:00"t in the IF statement is called a "time constant" and, again, looking in the documentation on the use of SAS date, time and datetime constants will help you understand more about the task you want/need to do.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 13 Jul 2010 04:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-Time-format/m-p/47904#M12911</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-07-13T04:21:27Z</dc:date>
    </item>
  </channel>
</rss>

