From: Murphy Choy on
Hi,

You can use dhms with hour, minute and second functions.

------Original Message------
From: Annie Lee
Sender: SAS(r) Discussion
To: SAS-L(a)LISTSERV.UGA.EDU
ReplyTo: Annie Lee
Subject: how to combine date and time to make it datetime
Sent: Dec 18, 2009 2:56 PM

Hi,

I would like to combine mydate and mytime to create mydatetime.
I would appreciate it if anyone would offer some help.



*** In excel:
mydate mytime
1/2/2009 12:00:00 AM 7:45:00 AM


*** After reading the data into SAS
mydate: Number 8 date9.
mytime: Number 8 time8.


mydate mytime
02JAN2009 7:45:00



*** Results I would like:
I would like to combine mydate and mytime to create mydatetime.

mydate mytime mydatetime
02JAN2009 7:45:00 02JAN2009:07:45:00



*** codes I tried and the (wrong) result I got.

mydate mytime mydatetime
02JAN2009 7:45:00 01JAN60:07:45:00




Options validVarName=any ;

PROC IMPORT OUT= WORK.one
DATAFILE= "c:\Service"
DBMS=EXCEL REPLACE;
SHEET="Service$";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;


data two;
set one;
myDateTime = datepart(mydate) + mytime;
run;


Sent from my BlackBerry Wireless Handheld

--
Regards,
Murphy Choy

Certified Advanced Programmer for SAS V9
Certified Basic Programmer for SAS V9
From: MAHESH KUMAR PEESARI on
HI,

USE DHMS function....


data datetime;
input mydate mytime;
informat mydate date9. mytime time8.;
format mydate date9. mytime time8. dt1 datetime32.;
dt1=DHMS(mydate,0,0,mytime);
cards;
02JAN2009 7:45:00
03JAN2009 8:45:00
04JAN2009 9:45:00
;
run;
proc print;
run;





On Fri, Dec 18, 2009 at 12:26 PM, Annie Lee <hummingbird10111(a)hotmail.com>wrote:

> Hi,
>
> I would like to combine mydate and mytime to create mydatetime.
> I would appreciate it if anyone would offer some help.
>
>
>
> *** In excel:
> mydate mytime
> 1/2/2009 12:00:00 AM 7:45:00 AM
>
>
> *** After reading the data into SAS
> mydate: Number 8 date9.
> mytime: Number 8 time8.
>
>
> mydate mytime
> 02JAN2009 7:45:00
>
>
>
> *** Results I would like:
> I would like to combine mydate and mytime to create mydatetime.
>
> mydate mytime mydatetime
> 02JAN2009 7:45:00 02JAN2009:07:45:00
>
>
>
> *** codes I tried and the (wrong) result I got.
>
> mydate mytime mydatetime
> 02JAN2009 7:45:00 01JAN60:07:45:00
>
>
>
>
> Options validVarName=any ;
>
> PROC IMPORT OUT= WORK.one
> DATAFILE= "c:\Service"
> DBMS=EXCEL REPLACE;
> SHEET="Service$";
> GETNAMES=YES;
> MIXED=NO;
> SCANTEXT=YES;
> USEDATE=YES;
> SCANTIME=YES;
> RUN;
>
>
> data two;
> set one;
> myDateTime = datepart(mydate) + mytime;
> run;
>



--
Thanks,
Mahesh P

*** FAILING TO PLAN IS PLANNING TO FAIL ***
From: "Data _null_;" on
Suppose the time was a duration. Would we create a datetime value as
the OP wants? If we would then the way the DHMS function is called
will yield different results. For example...

3077 data _null_;
3078 date = today();
3079 time = '25:30:30't;
3080 put time=time8.;
3081 h = hour(time);
3082 m = minute(time);
3083 s = second(time);
3084 put (h m s)(=);
3085 dt1 = dhms(date,h,m,s);
3086 dt2 = dhms(date,0,0,time);
3087 put (dt1 dt2) (=datetime.);
3088 run;

time=25:30:30
h=1 m=30 s=30
dt1=18DEC09:01:30:30 dt2=19DEC09:01:30:30


Does creating a datetime from a date and a duration make sense?



On 12/18/09, Murphy Choy <goladin(a)gmail.com> wrote:
> Hi,
>
> You can use dhms with hour, minute and second functions.
>
> ------Original Message------
> From: Annie Lee
> Sender: SAS(r) Discussion
> To: SAS-L(a)LISTSERV.UGA.EDU
> ReplyTo: Annie Lee
> Subject: how to combine date and time to make it datetime
> Sent: Dec 18, 2009 2:56 PM
>
> Hi,
>
> I would like to combine mydate and mytime to create mydatetime.
> I would appreciate it if anyone would offer some help.
>
>
>
> *** In excel:
> mydate mytime
> 1/2/2009 12:00:00 AM 7:45:00 AM
>
>
> *** After reading the data into SAS
> mydate: Number 8 date9.
> mytime: Number 8 time8.
>
>
> mydate mytime
> 02JAN2009 7:45:00
>
>
>
> *** Results I would like:
> I would like to combine mydate and mytime to create mydatetime.
>
> mydate mytime mydatetime
> 02JAN2009 7:45:00 02JAN2009:07:45:00
>
>
>
> *** codes I tried and the (wrong) result I got.
>
> mydate mytime mydatetime
> 02JAN2009 7:45:00 01JAN60:07:45:00
>
>
>
>
> Options validVarName=any ;
>
> PROC IMPORT OUT= WORK.one
> DATAFILE= "c:\Service"
> DBMS=EXCEL REPLACE;
> SHEET="Service$";
> GETNAMES=YES;
> MIXED=NO;
> SCANTEXT=YES;
> USEDATE=YES;
> SCANTIME=YES;
> RUN;
>
>
> data two;
> set one;
> myDateTime = datepart(mydate) + mytime;
> run;
>
>
> Sent from my BlackBerry Wireless Handheld
>
> --
> Regards,
> Murphy Choy
>
> Certified Advanced Programmer for SAS V9
> Certified Basic Programmer for SAS V9
>
From: Nathaniel Wooding on
Annie

As others have told you, the DHMS function will create a DateTime value but first, you need Hour, Minute, and Second:


Data Annie;

Time = '7:45:00't;
Date = '02JAN2009'd;

format date date. time time.;
Drop Hour Min Sec;

** first extract hour, minute, and second;
Hour = Hour ( time );
Min = Minute( time );
Sec = Second( time );


* Now, combine the pieces. Of course, I am using DateTime as both a variable name and a format;
DateTime = DHMS( Date , Hour , Min , Sec );
format DateTime Datetime20.;
run;

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Annie Lee
Sent: Friday, December 18, 2009 1:57 AM
To: SAS-L(a)LISTSERV.UGA.EDU
Subject: how to combine date and time to make it datetime

Hi,

I would like to combine mydate and mytime to create mydatetime.
I would appreciate it if anyone would offer some help.



*** In excel:
mydate mytime
1/2/2009 12:00:00 AM 7:45:00 AM


*** After reading the data into SAS
mydate: Number 8 date9.
mytime: Number 8 time8.


mydate mytime
02JAN2009 7:45:00



*** Results I would like:
I would like to combine mydate and mytime to create mydatetime.

mydate mytime mydatetime
02JAN2009 7:45:00 02JAN2009:07:45:00



*** codes I tried and the (wrong) result I got.

mydate mytime mydatetime
02JAN2009 7:45:00 01JAN60:07:45:00




Options validVarName=any ;

PROC IMPORT OUT= WORK.one
DATAFILE= "c:\Service"
DBMS=EXCEL REPLACE;
SHEET="Service$";
GETNAMES=YES;
MIXED=NO;
SCANTEXT=YES;
USEDATE=YES;
SCANTIME=YES;
RUN;


data two;
set one;
myDateTime = datepart(mydate) + mytime;
run;
CONFIDENTIALITY NOTICE: This electronic message contains
information which may be legally confidential and or privileged and
does not in any case represent a firm ENERGY COMMODITY bid or offer
relating thereto which binds the sender without an additional
express written confirmation to that effect. The information is
intended solely for the individual or entity named above and access
by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution, or use of the
contents of this information is prohibited and may be unlawful. If
you have received this electronic transmission in error, please
reply immediately to the sender that you have received the message
in error, and delete it. Thank you.
From: Murphy Choy on
Hi,

Wouldn't we use a kind of modulus function to extract the proper time?

On Dec 18, 2009 8:31pm, "Data _null_;" <iebupdte(a)gmail.com> wrote:
> Suppose the time was a duration. Would we create a datetime value as

> the OP wants? If we would then the way the DHMS function is called

> will yield different results. For example...



> 3077 data _null_;

> 3078 date = today();

> 3079 time = '25:30:30't;

> 3080 put time=time8.;

> 3081 h = hour(time);

> 3082 m = minute(time);

> 3083 s = second(time);

> 3084 put (hms)(=);

> 3085 dt1 = dhms(date,h,m,s);

> 3086 dt2 = dhms(date,0,0,time);

> 3087 put (dt1 dt2) (=datetime.);

> 3088 run;



> time=25:30:30

> h=1 m=30 s=30

> dt1=18DEC09:01:30:30 dt2=19DEC09:01:30:30





> Does creating a datetime from a date and a duration make sense?







> On 12/18/09, Murphy Choy goladin(a)gmail.com> wrote:

> > Hi,

> >

> > You can use dhms with hour, minute and second functions.

> >

> > ------Original Message------

> > From: Annie Lee

> > Sender: SAS(r) Discussion

> > To: SAS-L(a)LISTSERV.UGA.EDU

> > ReplyTo: Annie Lee

> > Subject: how to combine date and time to make it datetime

> > Sent: Dec 18, 2009 2:56 PM

> >

> > Hi,

> >

> > I would like to combine mydate and mytime to create mydatetime.

> > I would appreciate it if anyone would offer some help.

> >

> >

> >

> > *** In excel:

> > mydate mytime

> > 1/2/2009 12:00:00 AM 7:45:00 AM

> >

> >

> > *** After reading the data into SAS

> > mydate: Number 8 date9.

> > mytime: Number 8 time8.

> >

> >

> > mydate mytime

> > 02JAN2009 7:45:00

> >

> >

> >

> > *** Results I would like:

> > I would like to combine mydate and mytime to create mydatetime.

> >

> > mydate mytime mydatetime

> > 02JAN2009 7:45:00 02JAN2009:07:45:00

> >

> >

> >

> > *** codes I tried and the (wrong) result I got.

> >

> > mydate mytime mydatetime

> > 02JAN2009 7:45:00 01JAN60:07:45:00

> >

> >

> >

> >

> > Options validVarName=any ;

> >

> > PROC IMPORT OUT= WORK.one

> > DATAFILE= "c:\Service"

> > DBMS=EXCEL REPLACE;

> > SHEET="Service$";

> > GETNAMES=YES;

> > MIXED=NO;

> > SCANTEXT=YES;

> > USEDATE=YES;

> > SCANTIME=YES;

> > RUN;

> >

> >

> > data two;

> > set one;

> > myDateTime = datepart(mydate) + mytime;

> > run;

> >

> >

> > Sent from my BlackBerry Wireless Handheld

> >

> > --

> > Regards,

> > Murphy Choy

> >

> > Certified Advanced Programmer for SAS V9

> > Certified Basic Programmer for SAS V9

> >