Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Datetime to Unix timestamp in SAS

🎈 🎈 🎈
+1

    data ConvertDateToUnix;
        sas_date = '15JUL2018:12:30:45'dt; /* A random date in 2018 */
        unix_timestamp = (sas_date - '01JAN1970:00:00:00'dt) / 1;
        format sas_date datetime20.;
        put unix_timestamp=;
    run;        
        

Output:
1531657845
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this example, the SAS datetime value 15JUL2018:12:10:45 is converted to a Unix timestamp by subtracting the base date (01JAN1970:00:00:00) from it.
The difference is automatically given in seconds, and the Unix timestamp is calculated. The result is displayed in seconds since 1970-01-01, giving a Unix timestamp of '1531657845'.


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