<?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: converting character $4 to military time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407301#M99234</link>
    <description>why do datalines need to be included? Isn't the data being fed from 't'?</description>
    <pubDate>Wed, 25 Oct 2017 14:39:26 GMT</pubDate>
    <dc:creator>JamDOT</dc:creator>
    <dc:date>2017-10-25T14:39:26Z</dc:date>
    <item>
      <title>converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407267#M99223</link>
      <description>&lt;P&gt;I have tried the following in Windows 9.3:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
Varnew=input(Varold,time.);
FORMAT Varnew&amp;nbsp;time5.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The procedure runs, but only one observation and two variables result when there should be 1000s.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Numeric values have been converted to character values at the places given by:
(Line):(Column).
548:16
NOTE: There were 1 observations read from the data set have.
NOTE: The data set want&amp;nbsp;has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.04 seconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data is 4 characters long and in military time. I ultimately want to convert the observations to numeric format so I can group them by the hour. They are currently by the minute.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 14:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407267#M99223</guid>
      <dc:creator>JamDOT</dc:creator>
      <dc:date>2017-10-25T14:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407273#M99225</link>
      <description>&lt;P&gt;I don't know what you mean by military time?&amp;nbsp; This is where showing example data helps.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 13:53:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407273#M99225</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-25T13:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407277#M99227</link>
      <description>&lt;P&gt;From your log lines&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;NOTE&lt;/SPAN&gt;: There were &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; observations read &lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; the &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; Varold&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;NOTE: The data set Varnew has 1 observations and 2 variables.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it seems that you have not psted the right code.&lt;/P&gt;
&lt;P&gt;According to posted code varold and varnew are &lt;STRONG&gt;variables&lt;/STRONG&gt; not &lt;STRONG&gt;datasets&lt;/STRONG&gt; !&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 14:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407277#M99227</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-10-25T14:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407279#M99228</link>
      <description>&lt;P&gt;The character data is 4 characters long:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;0001&lt;/P&gt;&lt;P&gt;0002&lt;/P&gt;&lt;P&gt;0003&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;2356&lt;/P&gt;&lt;P&gt;2357&lt;/P&gt;&lt;P&gt;2358&lt;/P&gt;&lt;P&gt;2359&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to convert this character variable to a numeric time format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 14:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407279#M99228</guid>
      <dc:creator>JamDOT</dc:creator>
      <dc:date>2017-10-25T14:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407281#M99230</link>
      <description>&lt;P&gt;you are correct:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Numeric values have been converted to character values at the places given by:

(Line):(Column).

548:16

NOTE: There were 1 observations read from the data set have.

NOTE: The data set want has 1 observations and 2 variables.

NOTE: DATA statement used (Total process time):

real time 0.03 seconds

cpu time 0.04 seconds&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 14:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407281#M99230</guid>
      <dc:creator>JamDOT</dc:creator>
      <dc:date>2017-10-25T14:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407284#M99231</link>
      <description>&lt;P&gt;Your log messages do not match the program that you submitted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The TIME. format displays time in 'military time' (24-hour clock) but does not print a leading zero for 06:00.&lt;/P&gt;
&lt;P&gt;If you want the leading zero, use the TOD. format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you use the ANYDTTME. informat&amp;nbsp;to convert the strings to a time value, as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
length s $8.;
input s;                 /* a string */
t = input(s, ANYDTTME.); /* a (numeric) time value */
format t tod8.;          /* tell SAS to format the number as a 24-hour time */
datalines;
23:02:03
22:57:16
06:00:00
04:40:22
run;

proc print;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 14:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407284#M99231</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-10-25T14:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407301#M99234</link>
      <description>why do datalines need to be included? Isn't the data being fed from 't'?</description>
      <pubDate>Wed, 25 Oct 2017 14:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407301#M99234</guid>
      <dc:creator>JamDOT</dc:creator>
      <dc:date>2017-10-25T14:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407307#M99237</link>
      <description>&lt;P&gt;I used DATALINES so that everyone could see the data.&amp;nbsp; If you have a data set 'have' that contains the variable s, you can use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
SET have; /* the 'have' dataset contains&amp;nbsp;the character variable s */
t = input(s, ANYDTTME.); /* a (numeric) time value */
format t tod8.; /* tell SAS to format the number as a 24-hour time */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 14:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407307#M99237</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-10-25T14:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407322#M99245</link>
      <description>&lt;P&gt;605 data want;&lt;/P&gt;&lt;P&gt;606 set have;&lt;/P&gt;&lt;P&gt;607 Varnew=input(varold,anydttme.);&lt;/P&gt;&lt;P&gt;608 FORMAT&amp;nbsp;varnew tod8.;&lt;/P&gt;&lt;P&gt;609 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 1167321 observations read from the data set have.&lt;/P&gt;&lt;P&gt;NOTE: The data set&amp;nbsp;new has 1167321 observations and 113 variables.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 3.88 seconds&lt;/P&gt;&lt;P&gt;cpu time 3.52 seconds&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;610 proc freq data= want;&lt;/P&gt;&lt;P&gt;611 tables varnew/nocum;&lt;/P&gt;&lt;P&gt;612 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 1167321 observations read from the data set WORK.TRAVELTIME.&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE FREQ used (Total process time):&lt;/P&gt;&lt;P&gt;real time 1.24 seconds&lt;/P&gt;&lt;P&gt;cpu time 1.21 seconds&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;&lt;BR /&gt;
The FREQ Procedure
endtimeN Frequency Percent 
      [][][] /*3 column table here with blank cells*/
Frequency Missing = 1167321 


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; The output table still produces no data, BUT at least all observations are now being read.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 15:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407322#M99245</guid>
      <dc:creator>JamDOT</dc:creator>
      <dc:date>2017-10-25T15:13:20Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407328#M99250</link>
      <description>&lt;P&gt;If the data are really of the form&amp;nbsp;&lt;/P&gt;
&lt;P&gt;0001&lt;/P&gt;
&lt;P&gt;0002&lt;/P&gt;
&lt;P&gt;etc&lt;/P&gt;
&lt;P&gt;then those are invalid data strings, which is why the informat&amp;nbsp;is converting them to missing. Try creating a new string that inserts a colon between the second and third characters, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
length varOld $4. s $5.;
input varOld;                 /* a string */
s = catx(":", substr(varOld,1,2), substr(varOld,3,2));
t = input(s, ANYDTTME.); /* a (numeric) time value */
format t tod8.;          /* tell SAS to format the number as a 24-hour time */
datalines;
0001
0002
0003
2356
2357
2358
2359
;

proc print; run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 15:20:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407328#M99250</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-10-25T15:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407342#M99255</link>
      <description>&lt;P&gt;it works with datalines but when I put the set statement in, I get errors again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;24   data want;
25   set have;
26   length varold $4. varnew $5.;
27   input varold;
28   varnew =catx(":", substr(varold,1,2),substr(varold,3,2));
29   want=input(varnew,anydttme.);
30   format want tod8.;
31

ERROR: No DATALINES or INFILE statement.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set want may be incomplete.  When this step was stopped there were
         0 observations and 114 variables.
WARNING: Data set want was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.04 seconds

32   proc print;
33   run;

NOTE: There were 1 observations read from the data set want.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 15:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407342#M99255</guid>
      <dc:creator>JamDOT</dc:creator>
      <dc:date>2017-10-25T15:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407343#M99256</link>
      <description>&lt;P&gt;You can use the HHMMSS. informat to read a hhmm char value and translate it to a SAS time value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See code below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
  do charTime =
    "0001"
    ,"0002"
    ,"0003"
    ,"2356"
    ,"2357"
    ,"2358"
    ,"2359"
  ;
  sasTime = input(charTime, hhmmss4.);
  output;
 end;
 format sasTime tod8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 15:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407343#M99256</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-10-25T15:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: converting character $4 to military time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407344#M99257</link>
      <description>&lt;P&gt;where in the code does the data file go if I am not using datalines (very much a novice here)&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2017 15:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-character-4-to-military-time/m-p/407344#M99257</guid>
      <dc:creator>JamDOT</dc:creator>
      <dc:date>2017-10-25T15:48:42Z</dc:date>
    </item>
  </channel>
</rss>

