Date: Tue, 1 Mar 2011 07:59:10 -0500 Tom Abernathy "SAS(r) Discussion" Tom Abernathy Re: Working with time data in SAS XXXX

If you have read the digits as a number then you can use arithmetic.

input id \$ timen ;

hour = int(timen/100); minute = mod(timen,100); time = hms(hour,minute,0); format time time5.;

On Mon, 28 Feb 2011 17:02:03 -0600, Joe Matise <snoopy369@GMAIL.COM> wrote:

>Is the TIME field hhmm (so 1205 = 12:05, just after noon)? If so then you >can do several things. > >First, PUT it to a Z4 field, so: > >put(time, z4.) > >That gives you 0003 for that one digit one, etc. (which represents 00:03) > >Then if you split it you can produce: >cats(substr(put(time,z4.),1,2),':',substr(put,time,z4.),3,2),':00') >which can be read in with a TIME8. informat (with zero seconds appended >on). You could also use one of the ISO informats and skip the colons (just >append '00' to the end, as they do require seconds). > >Then hour of course is readily obtainable either directly (the >substr(...,1,2) portion is the hour), or using the HOUR() function. > >-Joe > >On Mon, Feb 28, 2011 at 4:48 PM, Dan Abner <dan.abner99@gmail.com> wrote: > >> Hello all, >> >> I have a field of 24 hr. unformat times (see below, notice that they have >> varying lengths (varying between 1 and 4 digits)). Can anyone suggest the >> easiest way to 1) convert these to SAS time values, and 2) create a new >> variable extracting just the hr part of the time (always rounding down is >> sufficient). >> >> Thank you! >> >> Dan >> >> >> obs ID TIME >> 1 C100014 1205 >> 2 C100018 1214 >> 3 C100018 1439 >> 4 C100022 1222 >> 5 C100025 1108 >> 6 C100025 1242 >> 7 C100026 1847 >> 8 C100027 1233 >> 9 C100027 2025 >> 10 C100029 1845 >> 11 C100030 422 >> 12 C100030 302 >> 13 C100031 1954 >> 14 C100031 1215 >> 15 C100032 2056 >> 16 C100033 1348 >> 17 C100034 1238 >> 18 C100034 534 >> 19 C100041 308 >> 20 C100042 1255 >> 21 C100042 1939 >> 22 C100044 1302 >> 23 C100046 1308 >> 24 C100050 1505 >> 25 C100050 1503 >> 26 C100057 1343 >> 27 C100059 209 >> 28 C100059 1544 >> 29 C100059 1104 >> 30 C100060 1335 >> 31 C100061 3 >> 32 C100065 2122 >> 33 C100066 1407 >> 34 C100072 1420 >> 35 C100074 1425 >>

Back to: Top of message | Previous page | Main SAS-L page