LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2011, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 28 Feb 2011 17:02:03 -0600
Reply-To:     Joe Matise <snoopy369@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Joe Matise <snoopy369@GMAIL.COM>
Subject:      Re: Working with time data in SAS XXXX
Comments: To: Dan Abner <dan.abner99@gmail.com>
In-Reply-To:  <201102282248.p1SM34eh023718@willow.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1

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