1
votes

I get a raw data file that has two fields: Start_Date and Start_Time. They are initially String variables, where Start_Date is in MM/DD/YYYY and Start_Time is in hh:mm:ss formats.

I'd like to combine these into a single Date variable (MM/DD/YYY hh:mm:ss). Here is the syntax I'm using but it's clumsy:

String MyDate(A20).
Compute MyDate = Concat(CHAR.SUBSTR 
(Start_Date, 4, 2), '-', CHAR.SUBSTR (Start_Date, 1,2), '-', 
CHAR.SUBSTR    (Start_Date, 7,4), ' ', Start_Time).
Execute.
Alter Type MyDate (DATETIME20).
Execute.
1

1 Answers

1
votes

Creating some example data:

data list list/Start_Date Start_Time (2a10).
begin data
"09/18/2018" "18:15:13"
end data.

Now use the following syntax to combine the two texts into one date-time variable:

compute StartDT=sum(number(Start_Date, adate10), number(Start_Time, time8)).
formats StartDT (datetime20).