<?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: Formatting Time in HH:MM:SS.sss into a if-then statement? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Formatting-Time-in-HH-MM-SS-sss-into-a-if-then-statement/m-p/511252#M2145</link>
    <description>&lt;P&gt;SAS is very simply typed. It knows about character and numeric fields. The simple replacement for your first statement would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt; &lt;SPAN class="token keyword"&gt;If&lt;/SPAN&gt; '&lt;SPAN class="token number"&gt;00&lt;/SPAN&gt;:&lt;SPAN class="token number"&gt;00&lt;/SPAN&gt;:&lt;SPAN class="token number"&gt;00.000't&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Time&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; '&lt;SPAN class="token number"&gt;06&lt;/SPAN&gt;:&lt;SPAN class="token number"&gt;00&lt;/SPAN&gt;:&lt;SPAN class="token number"&gt;00.000't&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Time&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'Night'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But that won't do what you want. Note, for example that if the time is exactly 6am, your next statement will override it with&amp;nbsp;&lt;EM&gt;Morning&lt;/EM&gt;. But that isn't right either! Because you've already implicitly defined Time as being 5 characters long&amp;nbsp;(&lt;EM&gt;Night&lt;/EM&gt;), it'll be&amp;nbsp;&lt;EM&gt;Morni&lt;/EM&gt;. But that won't work either, because you've already defined Time as numeric. So you need a new variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's how I would recommend you re-write it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data TimeofDay;
 set Airplane;
 length Timename $ 9;
 select;
    when('00:00:00't &amp;lt;= Time &amp;lt; '6:00:00't) Timename= 'Night';
    when('06:00:00't &amp;lt;= Time &amp;lt; '12:00:00't) Timename= 'Morning';
    when('12:00:00't &amp;lt;= Time &amp;lt; '18:00:00't) Timename= 'Afternoon';
    otherwise Timename = 'Evening';
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 08 Nov 2018 01:45:33 GMT</pubDate>
    <dc:creator>LaurieF</dc:creator>
    <dc:date>2018-11-08T01:45:33Z</dc:date>
    <item>
      <title>Formatting Time in HH:MM:SS.sss into a if-then statement?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Formatting-Time-in-HH-MM-SS-sss-into-a-if-then-statement/m-p/511248#M2143</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im using SAS&amp;nbsp;&lt;STRONG&gt;3.7 (Enterprise Edition)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The time a dataset I am using has the time in military time with a format of 00:00:00.000&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to format the Time in my data set into sections such as 6am-12pm = morning.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I run into this error when I run my code,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="x_sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="x_sasError"&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;71         Data TimeofDay;
 72             set Airplane ;
 73         
 74             If  00:00:00.000 &amp;lt;= Time &amp;lt;= 06:00:00.000 then Time= 'Night';
                      _
                      388
                      76
 75             If  06:00:00.000 &amp;lt;= Time &amp;lt;= 12:00:00.000 then Time= 'Morning';
                      _
                      388
                      76
 76             If  12:00:00.000 &amp;lt;= Time &amp;lt;= 18:00:00.000 then Time= 'Afternoon';
                      _
                      388
                      76
 77             If  18:00:00.000 &amp;lt;= Time &amp;lt;= 24:00:00.000 then Time= 'Evening';
                      _
                      388
                      76
 ERROR 388-185: Expecting an arithmetic operator.
 
 ERROR 76-322: Syntax error, statement will be ignored.&lt;/CODE&gt;&lt;/PRE&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="x_sasError"&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Here is my code:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data TimeofDay;
&amp;nbsp; &amp;nbsp; set Airplane ;
&amp;nbsp; &amp;nbsp;&amp;nbsp;If&amp;nbsp; 00:00:00.000 &amp;lt;= Time &amp;lt;= 06:00:00.000 then Time= 'Night';&amp;nbsp;
&amp;nbsp; &amp;nbsp; If&amp;nbsp; 06:00:00.000 &amp;lt;= Time &amp;lt;= 12:00:00.000 then Time= 'Morning';&amp;nbsp;
&amp;nbsp; &amp;nbsp; If&amp;nbsp; 12:00:00.000 &amp;lt;= Time &amp;lt;= 18:00:00.000 then Time= 'Afternoon';&amp;nbsp;
&amp;nbsp; &amp;nbsp; If&amp;nbsp; 18:00:00.000 &amp;lt;= Time &amp;lt;= 24:00:00.000 then Time= 'Evening';&amp;nbsp;
&amp;nbsp; &amp;nbsp; Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;My question is how do I format the time in the if then statement in order to not run into this error?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I've been reading solutions from other people but nothing has worked for me.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I would be grateful for any response.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 08 Nov 2018 00:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Formatting-Time-in-HH-MM-SS-sss-into-a-if-then-statement/m-p/511248#M2143</guid>
      <dc:creator>Tbaso</dc:creator>
      <dc:date>2018-11-08T00:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Time in HH:MM:SS.sss into a if-then statement?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Formatting-Time-in-HH-MM-SS-sss-into-a-if-then-statement/m-p/511252#M2145</link>
      <description>&lt;P&gt;SAS is very simply typed. It knows about character and numeric fields. The simple replacement for your first statement would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt; &lt;SPAN class="token keyword"&gt;If&lt;/SPAN&gt; '&lt;SPAN class="token number"&gt;00&lt;/SPAN&gt;:&lt;SPAN class="token number"&gt;00&lt;/SPAN&gt;:&lt;SPAN class="token number"&gt;00.000't&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Time&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt; '&lt;SPAN class="token number"&gt;06&lt;/SPAN&gt;:&lt;SPAN class="token number"&gt;00&lt;/SPAN&gt;:&lt;SPAN class="token number"&gt;00.000't&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Time&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'Night'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But that won't do what you want. Note, for example that if the time is exactly 6am, your next statement will override it with&amp;nbsp;&lt;EM&gt;Morning&lt;/EM&gt;. But that isn't right either! Because you've already implicitly defined Time as being 5 characters long&amp;nbsp;(&lt;EM&gt;Night&lt;/EM&gt;), it'll be&amp;nbsp;&lt;EM&gt;Morni&lt;/EM&gt;. But that won't work either, because you've already defined Time as numeric. So you need a new variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's how I would recommend you re-write it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data TimeofDay;
 set Airplane;
 length Timename $ 9;
 select;
    when('00:00:00't &amp;lt;= Time &amp;lt; '6:00:00't) Timename= 'Night';
    when('06:00:00't &amp;lt;= Time &amp;lt; '12:00:00't) Timename= 'Morning';
    when('12:00:00't &amp;lt;= Time &amp;lt; '18:00:00't) Timename= 'Afternoon';
    otherwise Timename = 'Evening';
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Nov 2018 01:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Formatting-Time-in-HH-MM-SS-sss-into-a-if-then-statement/m-p/511252#M2145</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2018-11-08T01:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting Time in HH:MM:SS.sss into a if-then statement?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Formatting-Time-in-HH-MM-SS-sss-into-a-if-then-statement/m-p/511451#M2171</link>
      <description>Thank you so much for your response! Great explanation.</description>
      <pubDate>Thu, 08 Nov 2018 17:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Formatting-Time-in-HH-MM-SS-sss-into-a-if-then-statement/m-p/511451#M2171</guid>
      <dc:creator>Tbaso</dc:creator>
      <dc:date>2018-11-08T17:35:09Z</dc:date>
    </item>
  </channel>
</rss>

