<?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: Calculating number of hours from midnight in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465592#M118768</link>
    <description>&lt;P&gt;If you store your am/pm variable as a boolean value, it's a simple calculation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input hour am_pm;
cards;
6 0
9 1
;
run;

data want;
set have;
your_hour = hour - 12 * am_pm;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If it's character, justa a very small change is needed:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
your_hour = hour - 12 * (am_pm = 'p.m.');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 May 2018 04:59:11 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-05-29T04:59:11Z</dc:date>
    <item>
      <title>Calculating number of hours from midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465585#M118763</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to calculate the&amp;nbsp;&lt;SPAN&gt;number of hours from midnight, with anything between 12 p.m. and 11:59 p.m. being negative. That is, 9 P.M. is “-3,”,while 6 A.M. is “6.” I tried the using something like the following, but I do not get the desired result. The variable I have is a time variable (12 hour clock), with another variable that indicates whether the time is in a.m. or p.m.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(fallaslp_mom_v2 - 60*60*12)/3600 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Any suggestions would be great. Thank you!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 04:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465585#M118763</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2018-05-29T04:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of hours from midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465591#M118767</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if ampm = "PM" then hours = time - 12; else hours = time;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 May 2018 04:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465591#M118767</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-05-29T04:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of hours from midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465592#M118768</link>
      <description>&lt;P&gt;If you store your am/pm variable as a boolean value, it's a simple calculation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input hour am_pm;
cards;
6 0
9 1
;
run;

data want;
set have;
your_hour = hour - 12 * am_pm;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If it's character, justa a very small change is needed:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
your_hour = hour - 12 * (am_pm = 'p.m.');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 May 2018 04:59:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465592#M118768</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-29T04:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of hours from midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465597#M118769</link>
      <description>&lt;P&gt;You are not telling us everything it seems.&lt;/P&gt;
&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  FALLASLP_MOM_V2= '09:00:00't;
  AMPM           = 'PM';
  HOUR           = (FALLASLP_MOM_V2 - 60*60*12*(AMPM='PM'))/3600;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;HOUR=-3&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Also, the 24-hour clock is the way to go.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 05:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465597#M118769</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-05-29T05:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of hours from midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465599#M118770</link>
      <description>&lt;P&gt;DATA TEMP;&lt;BR /&gt;INPUT D_TIME:time.;&lt;BR /&gt;FORMAT D_TIME midnight timeampm. Time_diff_midnight hhmm8.;&lt;BR /&gt;hr=hour(D_TIME);&lt;BR /&gt;%LET mid_night= %SYSFUNC(HMS(24,00,00));&lt;BR /&gt;midnight= &amp;amp;mid_night;&lt;/P&gt;&lt;P&gt;IF hr&amp;gt;=12 THEN Time_diff_midnight= D_TIME-&amp;amp;mid_night;&lt;BR /&gt;ELSE Time_diff_midnight=D_TIME;&lt;BR /&gt;CARDS;&lt;BR /&gt;12:30pm&lt;BR /&gt;11:10am&lt;BR /&gt;12:10am&lt;BR /&gt;5:10am&lt;BR /&gt;2:30pm&lt;BR /&gt;6:30pm&lt;BR /&gt;11:58pm&lt;BR /&gt;12:01am&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;PROC PRINT DATA=TEMP;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 05:51:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465599#M118770</guid>
      <dc:creator>mahesh146</dc:creator>
      <dc:date>2018-05-29T05:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating number of hours from midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465715#M118794</link>
      <description>&lt;P&gt;Thank you, everyone. I figured out something similar to one of the proposed solutions--thankfully they match up!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table survey as
	select participant_id,
		fallaslp,
		fallaslpampm,
	case
		when fallaslpampm = 1 then fallaslp/3600
		when fallaslpampm = 2 then (fallaslp - 60*60*12)/3600
	end as fallaslp_newtime
	from mydata
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 May 2018 13:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-number-of-hours-from-midnight/m-p/465715#M118794</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2018-05-29T13:54:46Z</dc:date>
    </item>
  </channel>
</rss>

