Convert SAS numeric to python datetime Convert SAS numeric to python datetime pandas pandas

Convert SAS numeric to python datetime


You'll need the built-in datetime module:

import datetimesastime = 1716470000epoch = datetime.datetime(1960, 1, 1)print(epoch + datetime.timedelta(seconds=sastime))

Which shows:

datetime.datetime(2014, 5, 23, 13, 13, 20) # is this right?

So if you have a dataframe with a column called sastime, you could do:

epoch = datetime.datetime(1960, 1, 1)# cast -s- to python int in case it's a string or a numpy.intdf['datetime'] = df['sastime'].apply(    lambda s: epoch + datetime.timedelta(seconds=int(s)))