<?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 create intervall time per hour or per 2 hour in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795728#M32950</link>
    <description>&lt;P&gt;Post the full log and actual code really helps as it highlights where the errors are in the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For starters - the time references in SAS are wrong.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Time values need to be in quotes and end in t, then SAS knows to interpret that value as a time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if '07:30't&amp;lt;=NHeure&amp;lt;='08:15't then T_Heure='07:30-08:15';
else if '08:30't &amp;lt;=NHeure&amp;lt;= '09:15't then T_Heure='08:30-09:15';&lt;BR /&gt;....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should get you started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS that is highly worth reading through:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413003"&gt;@Didi_b&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to create a new variable T_heure (Hour slice)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;These are examples of my trying. I've tried with and without quotations marks. But I keep getting errors.

if 07:30&amp;lt;=NHeure&amp;lt;=08:15 then T_Heure='07:30-08:15';
if 08:30&amp;lt;=NHeure&amp;lt;=09:15 then T_Heure='08:30-09:15';
if 09:30&amp;lt;=NHeure&amp;lt;=10:15 then T_Heure='09:30-10:15';
.
.
.
if NHeure=&amp;gt;16:30 then T_Heure='16:30+';

if Nheure in (07:30,08:15) then T_Heure=1;
else if Nheure in(08:30, 09:15) then T_Heure=2;
else if Nheure in(09:30, 10:15) then T_Heure=3;
else if Nheure in(10:30, 11:15) then T_Heure=4;
.
.
.
else if Nheure in (16:30) then T_Heure=10;

select (Nheure);
 when ("07:30", "07:45", "08:00", "08:15")  T_Heure=0;
  when ("08:30", "08:45", "09:00", "09:15")  T_Heure=1;
  when ("09:30", "09:45", "10:00", "10:15")  T_Heure=2;
 .
 . 
 .
when ("16:30")  T_Heure=9;
  otherwise T_Heure="";
end;&lt;BR /&gt;&lt;BR /&gt;h1=1 if Nheure is (07:30 to 08:15);&lt;BR /&gt;h1=2 if Nheure is (08:30 to 09:15);&lt;BR /&gt;h1=3 if Nheure is (09:30 to 10:15);&lt;BR /&gt;h1=4 if Nheure is (10:30 to 11:15);&lt;BR /&gt;h1=5 if Nheure is (11:30 to 12:15);&lt;BR /&gt;&lt;BR /&gt;Examples&amp;nbsp;of&amp;nbsp;errors:&lt;BR /&gt;&lt;BR /&gt;1068 if 07:30&amp;lt;=NHeure&amp;lt;=08:15 then T_Heure='07:30-08:15';&lt;BR /&gt;          -&lt;BR /&gt;          22&lt;BR /&gt;          76&lt;BR /&gt;1069 if 08:30&amp;lt;=NHeure&amp;lt;=09:15 then T_Heure='08:30-09:15';&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: &amp;lt;, &amp;lt;=, =, &amp;gt;, &amp;gt;=, EQ, GE, GT, LE, LT, NE,&lt;BR /&gt;NG, NL, ^=, ~=.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;1164 h1=1 if Nheure is (07:30 to 08:15);&lt;BR /&gt;--&lt;BR /&gt;388&lt;BR /&gt;76&lt;BR /&gt;1165 h1=2 if Nheure is (08:30 to 09:15);&lt;BR /&gt;          --&lt;BR /&gt;          388&lt;BR /&gt;           76&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;per hour or per 2hour.&lt;/P&gt;
&lt;P&gt;I've tried different ways with if and select fonction but I couldn't make it work. Could someone help me please. I'm really new to SAS and my data tables are too complicated to manipulate.&lt;/P&gt;
&lt;P&gt;My variable NHeure is (in SAS time format):&lt;/P&gt;
&lt;P&gt;07:30&lt;BR /&gt;07:45&lt;BR /&gt;08:00&lt;BR /&gt;08:15&lt;BR /&gt;08:45&lt;BR /&gt;09:00&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;16:30&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Feb 2022 18:02:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-02-11T18:02:58Z</dc:date>
    <item>
      <title>How to create intervall time per hour or per 2 hour</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795715#M32949</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to create a new variable T_heure (Hour slice)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;These are examples of my trying. I've tried with and without quotations marks. But I keep getting errors.

if 07:30&amp;lt;=NHeure&amp;lt;=08:15 then T_Heure='07:30-08:15';
if 08:30&amp;lt;=NHeure&amp;lt;=09:15 then T_Heure='08:30-09:15';
if 09:30&amp;lt;=NHeure&amp;lt;=10:15 then T_Heure='09:30-10:15';
.
.
.
if NHeure=&amp;gt;16:30 then T_Heure='16:30+';

if Nheure in (07:30,08:15) then T_Heure=1;
else if Nheure in(08:30, 09:15) then T_Heure=2;
else if Nheure in(09:30, 10:15) then T_Heure=3;
else if Nheure in(10:30, 11:15) then T_Heure=4;
.
.
.
else if Nheure in (16:30) then T_Heure=10;

select (Nheure);
 when ("07:30", "07:45", "08:00", "08:15")  T_Heure=0;
  when ("08:30", "08:45", "09:00", "09:15")  T_Heure=1;
  when ("09:30", "09:45", "10:00", "10:15")  T_Heure=2;
 .
 . 
 .
when ("16:30")  T_Heure=9;
  otherwise T_Heure="";
end;&lt;BR /&gt;&lt;BR /&gt;h1=1 if Nheure is (07:30 to 08:15);&lt;BR /&gt;h1=2 if Nheure is (08:30 to 09:15);&lt;BR /&gt;h1=3 if Nheure is (09:30 to 10:15);&lt;BR /&gt;h1=4 if Nheure is (10:30 to 11:15);&lt;BR /&gt;h1=5 if Nheure is (11:30 to 12:15);&lt;BR /&gt;&lt;BR /&gt;Examples&amp;nbsp;of&amp;nbsp;errors:&lt;BR /&gt;&lt;BR /&gt;1068 if 07:30&amp;lt;=NHeure&amp;lt;=08:15 then T_Heure='07:30-08:15';&lt;BR /&gt;          -&lt;BR /&gt;          22&lt;BR /&gt;          76&lt;BR /&gt;1069 if 08:30&amp;lt;=NHeure&amp;lt;=09:15 then T_Heure='08:30-09:15';&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: &amp;lt;, &amp;lt;=, =, &amp;gt;, &amp;gt;=, EQ, GE, GT, LE, LT, NE,&lt;BR /&gt;NG, NL, ^=, ~=.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;1164 h1=1 if Nheure is (07:30 to 08:15);&lt;BR /&gt;--&lt;BR /&gt;388&lt;BR /&gt;76&lt;BR /&gt;1165 h1=2 if Nheure is (08:30 to 09:15);&lt;BR /&gt;          --&lt;BR /&gt;          388&lt;BR /&gt;           76&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;per hour or per 2hour.&lt;/P&gt;
&lt;P&gt;I've tried different ways with if and select fonction but I couldn't make it work. Could someone help me please. I'm really new to SAS and my data tables are too complicated to manipulate.&lt;/P&gt;
&lt;P&gt;My variable NHeure is (in SAS time format):&lt;/P&gt;
&lt;P&gt;07:30&lt;BR /&gt;07:45&lt;BR /&gt;08:00&lt;BR /&gt;08:15&lt;BR /&gt;08:45&lt;BR /&gt;09:00&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;16:30&lt;/P&gt;</description>
      <pubDate>Fri, 11 Feb 2022 17:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795715#M32949</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-11T17:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to create intervall time per hour or per 2 hour</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795728#M32950</link>
      <description>&lt;P&gt;Post the full log and actual code really helps as it highlights where the errors are in the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For starters - the time references in SAS are wrong.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Time values need to be in quotes and end in t, then SAS knows to interpret that value as a time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if '07:30't&amp;lt;=NHeure&amp;lt;='08:15't then T_Heure='07:30-08:15';
else if '08:30't &amp;lt;=NHeure&amp;lt;= '09:15't then T_Heure='08:30-09:15';&lt;BR /&gt;....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should get you started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS that is highly worth reading through:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413003"&gt;@Didi_b&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to create a new variable T_heure (Hour slice)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;These are examples of my trying. I've tried with and without quotations marks. But I keep getting errors.

if 07:30&amp;lt;=NHeure&amp;lt;=08:15 then T_Heure='07:30-08:15';
if 08:30&amp;lt;=NHeure&amp;lt;=09:15 then T_Heure='08:30-09:15';
if 09:30&amp;lt;=NHeure&amp;lt;=10:15 then T_Heure='09:30-10:15';
.
.
.
if NHeure=&amp;gt;16:30 then T_Heure='16:30+';

if Nheure in (07:30,08:15) then T_Heure=1;
else if Nheure in(08:30, 09:15) then T_Heure=2;
else if Nheure in(09:30, 10:15) then T_Heure=3;
else if Nheure in(10:30, 11:15) then T_Heure=4;
.
.
.
else if Nheure in (16:30) then T_Heure=10;

select (Nheure);
 when ("07:30", "07:45", "08:00", "08:15")  T_Heure=0;
  when ("08:30", "08:45", "09:00", "09:15")  T_Heure=1;
  when ("09:30", "09:45", "10:00", "10:15")  T_Heure=2;
 .
 . 
 .
when ("16:30")  T_Heure=9;
  otherwise T_Heure="";
end;&lt;BR /&gt;&lt;BR /&gt;h1=1 if Nheure is (07:30 to 08:15);&lt;BR /&gt;h1=2 if Nheure is (08:30 to 09:15);&lt;BR /&gt;h1=3 if Nheure is (09:30 to 10:15);&lt;BR /&gt;h1=4 if Nheure is (10:30 to 11:15);&lt;BR /&gt;h1=5 if Nheure is (11:30 to 12:15);&lt;BR /&gt;&lt;BR /&gt;Examples&amp;nbsp;of&amp;nbsp;errors:&lt;BR /&gt;&lt;BR /&gt;1068 if 07:30&amp;lt;=NHeure&amp;lt;=08:15 then T_Heure='07:30-08:15';&lt;BR /&gt;          -&lt;BR /&gt;          22&lt;BR /&gt;          76&lt;BR /&gt;1069 if 08:30&amp;lt;=NHeure&amp;lt;=09:15 then T_Heure='08:30-09:15';&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: &amp;lt;, &amp;lt;=, =, &amp;gt;, &amp;gt;=, EQ, GE, GT, LE, LT, NE,&lt;BR /&gt;NG, NL, ^=, ~=.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;1164 h1=1 if Nheure is (07:30 to 08:15);&lt;BR /&gt;--&lt;BR /&gt;388&lt;BR /&gt;76&lt;BR /&gt;1165 h1=2 if Nheure is (08:30 to 09:15);&lt;BR /&gt;          --&lt;BR /&gt;          388&lt;BR /&gt;           76&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;per hour or per 2hour.&lt;/P&gt;
&lt;P&gt;I've tried different ways with if and select fonction but I couldn't make it work. Could someone help me please. I'm really new to SAS and my data tables are too complicated to manipulate.&lt;/P&gt;
&lt;P&gt;My variable NHeure is (in SAS time format):&lt;/P&gt;
&lt;P&gt;07:30&lt;BR /&gt;07:45&lt;BR /&gt;08:00&lt;BR /&gt;08:15&lt;BR /&gt;08:45&lt;BR /&gt;09:00&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;16:30&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Feb 2022 18:02:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795728#M32950</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-11T18:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create intervall time per hour or per 2 hour</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795729#M32951</link>
      <description>&lt;P&gt;Is NHeure an actual SAS Time variable?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Feb 2022 18:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795729#M32951</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-02-11T18:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to create intervall time per hour or per 2 hour</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795734#M32952</link>
      <description>&lt;P&gt;Here is an example i created to help you out .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data testingT;&lt;BR /&gt;/*To reference Dates in code use this format "date"d (followed by a d ) */&lt;BR /&gt;/*To reference Times in code use this format "Time"t (followed by a t)*/&lt;BR /&gt;/*To reference DateTime in code use this format "DateTime"dt (followed b a dt)*/&lt;BR /&gt;endt='08:15't; &lt;BR /&gt;starttime="07:15"t;&lt;BR /&gt;/*use the intck to compare date values year , month and even hour;*/&lt;BR /&gt;hdiff=intck("hour",starttime,endt,"C");&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Feb 2022 18:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795734#M32952</guid>
      <dc:creator>CarmineVerrell</dc:creator>
      <dc:date>2022-02-11T18:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create intervall time per hour or per 2 hour</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795736#M32953</link>
      <description>&lt;P&gt;Hi yes, First converted to a SAS time Value with this&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NHeure=input(translate(Heure,':','H'),time15.);
format NHeure tod5.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Feb 2022 18:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795736#M32953</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-11T18:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to create intervall time per hour or per 2 hour</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795740#M32954</link>
      <description>&lt;P&gt;Hi, thank you so much for the tips.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How could accept multiples propositions that work as a solution?&lt;/P&gt;
&lt;P&gt;When I accept one, I can't no longer accept other solution&amp;nbsp; as a solution too.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Feb 2022 18:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-create-intervall-time-per-hour-or-per-2-hour/m-p/795740#M32954</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-11T18:22:01Z</dc:date>
    </item>
  </channel>
</rss>

