Help using Base SAS procedures

merge "date" and "time" as a variable "date and time"

Reply
Frequent Contributor
Posts: 128

merge "date" and "time" as a variable "date and time"

I have a variable "date" and a "time" for each patient.
I want to merge them to one variable "date and time", is any way I can do that?

Thanks! Message was edited by: Ken_oy
Respected Advisor
Posts: 3,777

Re: merge "date" and "time" as a variable "date and time"

Are they SAS dates and times?

If so then you just need to convert them to the proper units and add them together.

[pre]datetime = dhms(date,0,0,time);[/pre]

Is commonly used.
Frequent Contributor
Posts: 128

Re: merge "date" and "time" as a variable "date and time"

Thanks for your quick reply.

I test the code from you, it works for SAS date and SAS time.

But my problem is, I have character variables instead, all strings

i.g.: "date"="01/01/2007"; "time"="13:00:00"

How to transfer all these strings into a SAS date9. format? thanks!
Frequent Contributor
Posts: 128

Re: merge "date" and "time" as a variable "date and time"

OK, for now I fixed it with your help.

1. transfer those strings into a SAS date:

sas_date=input(substr(string_date, 1, 10), mmddyy10.);

2. using data_null_'s code:

it works now!

Thanks!
Ask a Question
Discussion stats
  • 3 replies
  • 175 views
  • 0 likes
  • 2 in conversation