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 (March 1996, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 13 Mar 1996 11:08:12 PST
Reply-To:     TWB2%Rates%FAR@GO50.COMP.PGE.COM
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         TWB2%Rates%FAR@GO50.COMP.PGE.COM
Subject:      Re: Time Conversion

I missed the original question, but it has been excerpted twice and I understand it like this: the raw data has a value like 01:17:32 PM. Someone read these into two character variables and now someone else wants to construct a SAS time value (other posters assumed 01:17:32 is already a SAS time value--that is not obvious to me from the quoted question). I would code something like:

DATA NEW; SET OLD; * First, convert '01:17:32' to a SAS time value; HALFWORK=INPUT(CHARTIME,TIME8.); * Now, adjust for AM/PM; * Add the number of seconds in 12 hours to the time value * if the AMPM variable is PM; IF AMPM EQ 'AM' THEN TIME=HALFWORK; ELSE TIME=HALFWORK+(12*60*60); RUN;

Naturally, my production code would not have the temporary variable HALFWORK, and I would use 43200 rather than (12*60*60), with a comment explaining the value. Tim Berryhill - Contract Programmer and General Wizard TWB2@PGE.COM or Frequently at Pacific Gas & Electric Co., San Francisco The correlation coefficient between their views and my postings is slightly less than 0 ----------------------[Reply - Original Message]---------------------- (Michael Babyak) wrote: >Dear SAS folks, > >I was wondering if anyone could offer us some advice on the >following problem: > >We have two variables, one for time of day in hh:mm:ss >format, which was entered in clock time (ie, 1 through 12 >hours), and a second coded as AM or PM. We'd like to >recode these two variables into one military time variable. >Can anyone offer a way to do this? > >Many thanks in advance. > >Mike Babyak > > >-- >Mike Babyak, PhD >Behavioral Cardiology Laboratory >Department of Psychiatry >Box 3119 >Duke University Medical Center >Durham, NC 27710 >(919) 684-8843 >(919) 684-8629 >

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