<?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: Trying to change a numeric field to a SAS time value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679024#M205034</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;TO_CHAR(TIME)&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you using PROC SQL with a passthru to Oracle or some other database?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not, in a SAS data step, you can use the SAS function HMS(), as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;h=floor(time/10000);
m=floor((time-h*10000)/100);
s=mod(floor(time),100);
time_value = hms(h,m,s);

format time_value time8.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Aug 2020 01:08:40 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-08-25T01:08:40Z</dc:date>
    <item>
      <title>Trying to change a numeric field to a SAS time value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679019#M205033</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a time variable in one of my datasets and I am trying to store it as a SAS time value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the dataset, the time variable is numeric. Example data: 114634.0766435&lt;/P&gt;&lt;P&gt;What I am trying to capture from that field is 11:46:34 as that represents the Hours(military time), mins and seconds, and then changing it to a SAS time value so I can do time functions on it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to first change it to a character using the code below:&lt;/P&gt;&lt;P&gt;TO_CHAR(TIME)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I am stuck from here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2020 00:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679019#M205033</guid>
      <dc:creator>lauren2</dc:creator>
      <dc:date>2020-08-25T00:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to change a numeric field to a SAS time value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679024#M205034</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;TO_CHAR(TIME)&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you using PROC SQL with a passthru to Oracle or some other database?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not, in a SAS data step, you can use the SAS function HMS(), as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;h=floor(time/10000);
m=floor((time-h*10000)/100);
s=mod(floor(time),100);
time_value = hms(h,m,s);

format time_value time8.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Aug 2020 01:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679024#M205034</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-25T01:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to change a numeric field to a SAS time value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679041#M205037</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much! That worked. &amp;nbsp;Yes I was using a proc sql with a passthru to oracle, but wrote the SAS step instead. One more question if you have the time. I now have one date field in format date9. and one time field in format time8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I combine these two variables into one and make it a date time field?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2020 03:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679041#M205037</guid>
      <dc:creator>lauren2</dc:creator>
      <dc:date>2020-08-25T03:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to change a numeric field to a SAS time value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679105#M205058</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/343043"&gt;@lauren2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks so much! That worked. &amp;nbsp;Yes I was using a proc sql with a passthru to oracle, but wrote the SAS step instead. One more question if you have the time. I now have one date field in format date9. and one time field in format time8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can I combine these two variables into one and make it a date time field?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can use the DHMS function in SAS to create a SAS datetime field but is that what you want?&lt;/P&gt;
&lt;P&gt;dt = dhms(date,0,0,time); where DATE is a valid SAS date valued variable and Time is a SAS time valued variable. The format takes date, hour, minute and second parameters (hence the function name) and time values in SAS are numbers of seconds, so you use zero for the hour and minute components)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or is this again pass-through to Oracle (where I haven't a clue)&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2020 07:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679105#M205058</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-25T07:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to change a numeric field to a SAS time value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679111#M205064</link>
      <description>&lt;P&gt;You can use a custom picture format to make the conversion shorter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture dbtime
  low-high = '99:99:99'
;
run;

data want;
set have;
sastime = input(put(numtime,dbtime.),time8.) + mod(numtime,1);
format sastime time16.7;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Aug 2020 09:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679111#M205064</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-25T09:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to change a numeric field to a SAS time value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679120#M205066</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/343043"&gt;@lauren2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks so much! That worked. &amp;nbsp;Yes I was using a proc sql with a passthru to oracle, but wrote the SAS step instead. One more question if you have the time. I now have one date field in format date9. and one time field in format time8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can I combine these two variables into one and make it a date time field?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, you use the &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p1b9d1kbo0czoxn1ouj1kcxwqzn1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;DHMS()&lt;/A&gt; function.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2020 11:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679120#M205066</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-25T11:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to change a numeric field to a SAS time value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679196#M205092</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;I can use a SAS step or pass through to Oracle, but I should use SAS since SQL can only handle date time fields. Let me start from the beginning. In my dataset, I have a date variable that is stored as a number and it looks like 20200728. So the date is written in YYYYMMDD, but it is not stored as a SAS date value. I also have a time variable that is also stored as a number and it looks like 114634.07664, but it is not stored as a SAS time value. What I want from that field is 11:46:34. My goal, is to combine both of these fields into a SAS date time value. From there, I can change the format to whatever I need.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2020 16:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-change-a-numeric-field-to-a-SAS-time-value/m-p/679196#M205092</guid>
      <dc:creator>lauren2</dc:creator>
      <dc:date>2020-08-25T16:26:01Z</dc:date>
    </item>
  </channel>
</rss>

