Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Unix Timestamp to Datetime in SAS

How to convert Unix timestamp to Datetime in SAS

🎈 🎈 🎈
+1

    data ConvertUnixToDate;
        unix_timestamp = 1465292714;
        sas_date = intnx('SECOND', '01JAN1970'd, unix_timestamp, 'same');
        format sas_date datetime20.;
        put sas_date=;
    run;        
        

Output:
2016-06-07 09:45:14
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this example of Unix timestamp to date conversion in SAS, the Unix timestamp 1465292714 is converted into a SAS date by using the INTNX function. The 'SECOND' argument specifies that we are shifting by seconds, and '01JAN1970'd is the base date (Unix epoch). The result is formatted using the datetime20. format, which displays the date and time.
This will output the human-readable date which in this case would be 2016-06-07 09:45:14.



Other useful SAS date functions

Function Description Example
intnx() Advances a date, time, or datetime value by a specified number of intervals. intnx('SECOND', '01JAN1970'd, 1514764800) returns 01JAN2018:00:00:00
intck() Returns the number of intervals between two dates, times, or datetime values. intck('SECOND', '01JAN1970:00:00:00'dt, '15JUL2018:12:30:45'dt) returns the Unix timestamp 1531656645.
today() Returns the current date as a SAS date value. today() returns the current date.
time() Returns the current time as a SAS time value. time() returns the current time.
datetime() Returns the current date and time as a SAS datetime value. datetime() returns the current datetime.
datepart() Extracts the date part from a SAS datetime value. datepart('15JUL2018:12:30:45'dt) returns 15JUL2018.
timepart() Extracts the time part from a SAS datetime value. timepart('15JUL2018:12:30:45'dt) returns 12:30:45.
mdy() Creates a SAS date value from month, day, and year. mdy(7, 15, 2018) returns the date 15JUL2018.
hms() Creates a SAS time value from hour, minute, and second. hms(12, 30, 45) returns the time 12:30:45.
dhms() Creates a SAS datetime value from date, hour, minute, and second. dhms('15JUL2018'd, 12, 30, 45) returns 15JUL2018:12:30:45.
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder