<?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: convert char time to SAS time format in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/793200#M32748</link>
    <description>&lt;P&gt;Ignore the INFILE and INPUT. Those are for reading data from a text file.&amp;nbsp; That was just included in the example so there was some actual data to test with.&amp;nbsp; If you are getting the data from an existing dataset with a SET statement you don't need them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note if you are using PROC IMPORT to read a text file you can convert to writing your own data step to read the file instead.&amp;nbsp; Then you can avoid the issues caused by PROC IMPORT having the GUESS what the data is.&amp;nbsp; Then you would want to have INFILE and INPUT statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The TRUNCOVER option is to keep SAS from running to the next line when it runs out of data to feed to the INPUT statement from the current line.&amp;nbsp; The default is FLOWOVER when jumps to the next when you run out of data.&amp;nbsp; There is also the MISSOVER option which you almost never want to use because it could cause some useful data to be skipped.&amp;nbsp;&amp;nbsp;MISSOVER can be made to work like TRUNCOVER if you are careful to only use LIST MODE input style.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The CARDS keyword (also known as DATALINES) is to indicate that the file being read is the in-line data that follows the CARDS/DATALINE statement at the end of the data step.&amp;nbsp; Using this allows you to use INFILE options like TRUNCOVER when using in-line data lines.&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jan 2022 19:49:15 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-01-28T19:49:15Z</dc:date>
    <item>
      <title>convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792919#M32698</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to SAS and I'm looking to convert my data into SAS format&lt;/P&gt;&lt;P&gt;a sample&lt;/P&gt;&lt;P&gt;LineName Day hour call&lt;/P&gt;&lt;P&gt;x 05/01/2022 09H30 5&lt;/P&gt;&lt;P&gt;x 05/01/2022 09H45 3&lt;/P&gt;&lt;P&gt;x 05/01/2022 10H00 10&lt;/P&gt;&lt;P&gt;y 05/01/2022 09H30 1&lt;/P&gt;&lt;P&gt;y 05/01/2022 09H45 9&lt;/P&gt;&lt;P&gt;y 05/01/2022 10H00 7&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;x 31/01/2022 09H30 0&lt;/P&gt;&lt;P&gt;x 31/01/2022 09H45 9&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;My day and hour format and informat are char. I want to have it in SAS time format.&lt;/P&gt;&lt;P&gt;I was able to format my var day into SAS format. but I couldn't do for my var hour.&lt;/P&gt;&lt;P&gt;Could someone help me please?&lt;/P&gt;&lt;P&gt;the proc content shows&lt;/P&gt;&lt;P&gt;var type len format informat&lt;/P&gt;&lt;P&gt;hour char 15 $15. $15.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 16:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792919#M32698</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-01-27T16:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792923#M32699</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;time = hms(input(substr(hour, 1,2), 8.), input(substr(hour, 4, 2),8.), 0);&lt;/CODE&gt;&lt;/PRE&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm new to SAS and I'm looking to convert my data into SAS format&lt;/P&gt;
&lt;P&gt;a sample&lt;/P&gt;
&lt;P&gt;LineName Day hour call&lt;/P&gt;
&lt;P&gt;x 05/01/2022 09H30 5&lt;/P&gt;
&lt;P&gt;x 05/01/2022 09H45 3&lt;/P&gt;
&lt;P&gt;x 05/01/2022 10H00 10&lt;/P&gt;
&lt;P&gt;y 05/01/2022 09H30 1&lt;/P&gt;
&lt;P&gt;y 05/01/2022 09H45 9&lt;/P&gt;
&lt;P&gt;y 05/01/2022 10H00 7&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;x 31/01/2022 09H30 0&lt;/P&gt;
&lt;P&gt;x 31/01/2022 09H45 9&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;My day and hour format and informat are char. I want to have it in SAS time format.&lt;/P&gt;
&lt;P&gt;I was able to format my var day into SAS format. but I couldn't do for my var hour.&lt;/P&gt;
&lt;P&gt;Could someone help me please?&lt;/P&gt;
&lt;P&gt;the proc content shows&lt;/P&gt;
&lt;P&gt;var type len format informat&lt;/P&gt;
&lt;P&gt;hour char 15 $15. $15.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 16:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792923#M32699</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-27T16:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792926#M32701</link>
      <description>&lt;P&gt;So if HOUR is character with length of 15 (the format and/or informat attached play no role) then use INPUT() function to convert to time.&amp;nbsp; You will need to change the letter H into a : if you want to use the TIME informat.&lt;/P&gt;
&lt;P&gt;Attach a time type FORMAT to your new numeric variable so it prints in a way that humans can understand.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  time = input(translate(hour,':','H'),time15.);
  format time tod5.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jan 2022 17:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792926#M32701</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-27T17:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792931#M32703</link>
      <description>Thanks Reeza, but it doesn't work it gives the same output for every set of hour.&lt;BR /&gt;I get&lt;BR /&gt;hour Time&lt;BR /&gt;09H30 43260&lt;BR /&gt;09H45 43260&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;11H00 43260&lt;BR /&gt;11H15 43260&lt;BR /&gt;&lt;BR /&gt;and when I format it gives me&lt;BR /&gt;time&lt;BR /&gt;12:01&lt;BR /&gt;12:01&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;12:01</description>
      <pubDate>Thu, 27 Jan 2022 17:20:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792931#M32703</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-01-27T17:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792932#M32704</link>
      <description>Thanks Tom! it worked</description>
      <pubDate>Thu, 27 Jan 2022 17:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792932#M32704</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-01-27T17:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792980#M32712</link>
      <description>&lt;P&gt;Works fine when tested with what you've posted.&lt;/P&gt;
&lt;P&gt;However, glad&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;solution worked for you already.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input LineName $ Day : mmddyy10. hour $ call;
time = hms(input(substr(hour, 1,2), 8.), input(substr(hour, 4, 2),8.), 0);
format time time.;
cards;
x 05/01/2022 09H30 5
x 05/01/2022 09H45 3
x 05/01/2022 10H00 10
y 05/01/2022 09H30 1
y 05/01/2022 09H45 9
y 05/01/2022 10H00 7
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Reeza_0-1643312677681.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67939i94168537C4526E92/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Reeza_0-1643312677681.png" alt="Reeza_0-1643312677681.png" /&gt;&lt;/span&gt;&lt;/P&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;Thanks Reeza, but it doesn't work it gives the same output for every set of hour.&lt;BR /&gt;I get&lt;BR /&gt;hour Time&lt;BR /&gt;09H30 43260&lt;BR /&gt;09H45 43260&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;11H00 43260&lt;BR /&gt;11H15 43260&lt;BR /&gt;&lt;BR /&gt;and when I format it gives me&lt;BR /&gt;time&lt;BR /&gt;12:01&lt;BR /&gt;12:01&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;12:01&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 19:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/792980#M32712</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-27T19:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/793197#M32747</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; thanks a lot for your input.&lt;BR /&gt;It works when I run the code as you shared.&lt;BR /&gt;The problem is that I don't know how to apply it to all my data table with 13 variables a multiples rows. But I've tried multiples ways&lt;BR /&gt;&lt;BR /&gt;The sample I've shown is from my data table I import into SAS by&lt;BR /&gt;proc import&lt;BR /&gt;The thing is, I'm really new to SAS. There are things I don't understand yet.&lt;BR /&gt;I'm not familiar with the infile statement.&lt;BR /&gt;&lt;BR /&gt;I add that to my program :&lt;BR /&gt;time = hms(input(substr(hour, 1,2), 8.), input(substr(hour, 4, 2),8.), 0);&lt;BR /&gt;format time time.; but it didn't work.&lt;BR /&gt;&lt;BR /&gt;infile cards truncover; why cards truncover?</description>
      <pubDate>Fri, 28 Jan 2022 19:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/793197#M32747</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-01-28T19:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/793200#M32748</link>
      <description>&lt;P&gt;Ignore the INFILE and INPUT. Those are for reading data from a text file.&amp;nbsp; That was just included in the example so there was some actual data to test with.&amp;nbsp; If you are getting the data from an existing dataset with a SET statement you don't need them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note if you are using PROC IMPORT to read a text file you can convert to writing your own data step to read the file instead.&amp;nbsp; Then you can avoid the issues caused by PROC IMPORT having the GUESS what the data is.&amp;nbsp; Then you would want to have INFILE and INPUT statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The TRUNCOVER option is to keep SAS from running to the next line when it runs out of data to feed to the INPUT statement from the current line.&amp;nbsp; The default is FLOWOVER when jumps to the next when you run out of data.&amp;nbsp; There is also the MISSOVER option which you almost never want to use because it could cause some useful data to be skipped.&amp;nbsp;&amp;nbsp;MISSOVER can be made to work like TRUNCOVER if you are careful to only use LIST MODE input style.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The CARDS keyword (also known as DATALINES) is to indicate that the file being read is the in-line data that follows the CARDS/DATALINE statement at the end of the data step.&amp;nbsp; Using this allows you to use INFILE options like TRUNCOVER when using in-line data lines.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 19:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/793200#M32748</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-28T19:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/793216#M32749</link>
      <description>Okay thanks a lot &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;.&lt;BR /&gt;It is an unusual Excel file from which I use the proc import.&lt;BR /&gt;I'll try to post the program I used&lt;BR /&gt;</description>
      <pubDate>Fri, 28 Jan 2022 20:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/793216#M32749</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-01-28T20:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/793222#M32750</link>
      <description>&lt;P&gt;If you have a real XLSX file then you won't have any flexibility in converting it into a SAS dataset.&lt;/P&gt;
&lt;P&gt;But if you have a CSV file (which is just a text file and has nothing in particular to do with Excel) then you can read it directly.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 20:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/793222#M32750</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-28T20:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/794263#M32810</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;Sorry for posting a bit late&lt;/P&gt;&lt;P&gt;Here the program I use with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Solution. I've tried to replace with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;solution whithout succeding&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc import datafile="filepath\file_2022-01-12.xls" dbms=xls out=table_name replace;&lt;BR /&gt;sheet="sheetname";&lt;BR /&gt;namerow=7;&lt;BR /&gt;startrow=10;&lt;BR /&gt;Endrow=934;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data test1;&lt;BR /&gt;set Work.table_name;&lt;/P&gt;&lt;P&gt;if Day="" then Day='12/01/2022';&lt;BR /&gt;if Day="Sous Total" then delete;&lt;BR /&gt;else Day='12/01/2022';&lt;BR /&gt;NJour=input(Day,anydtdte12.);&lt;/P&gt;&lt;P&gt;format NDay MMDDYY10.;&lt;BR /&gt;NHour=input(translate(Hour,':','H'),time15.);&lt;BR /&gt;format NHour tod5.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*time=hms(input(substr(Jour, 1,2),8.),input(substr(Jour, 4,2),8.), 0);&lt;BR /&gt;format time time.;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;retain Line;&lt;BR /&gt;if not missing(LineName) then Line=LineName;&lt;BR /&gt;else LineName=Line;&lt;BR /&gt;drop Line Day Hour B D J P;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 16:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/794263#M32810</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-03T16:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/794265#M32811</link>
      <description>&lt;P&gt;Be careful with using the ANYDTDTE informat. Depending on locale, your 12/01/2022 can end up as 1st of December or 12th of January. Rather use DDMMYY or MMDDYY instead, to be on the safe side.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 16:18:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/794265#M32811</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-03T16:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: convert char time to SAS time format</title>
      <link>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/794268#M32812</link>
      <description>Okay thanks. I've tried it at the time but it didn't work that's why I used the anydate fonction. But today it did work with the MMDDYY10. fonction. Thanks</description>
      <pubDate>Thu, 03 Feb 2022 16:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/convert-char-time-to-SAS-time-format/m-p/794268#M32812</guid>
      <dc:creator>Didi_b</dc:creator>
      <dc:date>2022-02-03T16:24:46Z</dc:date>
    </item>
  </channel>
</rss>

