Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAS datetime format / informat - Milliseconds since Unix epoch

Tags:

datetime

sas

I need to use SAS to input a string containing a time value, expressed as the number of milliseconds since the Unix epoch.

E.g., I have an input string of "1278486000000" and I want to extract the date value "2010-07-07".

Basically, I need the SAS informat version of this online tool.

It's a fairly common timestamp, so I guess there's an inbuilt SAS format for this. I know about the difference between SAS' 1960 epoch and the standard Unix 1970 epoch however, so I'm supposing that might complicate matters.

If there is no standard informat, how would I go about creating one?

like image 648
Nossidge Avatar asked Nov 15 '25 08:11

Nossidge


1 Answers

I don't know about an informat, but this is certainly doable with a function call.

data _null_;
x="1278486000000";
y=datepart(intnx('dtyear',input(x,best32.)/1000,10,'s'));
put y= date.;
run;

We pretend it's a 1960 epoch and then adjust to a 1970 epoch. This will be slightly off of your answer, because your answer is adjusted for timezone. You can adjust the SAS value for timezone as well, separately, if you wish.

like image 73
Joe Avatar answered Nov 17 '25 22:11

Joe