Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert number to a SAS datetime value

Status
Not open for further replies.

AlbertKM

Programmer
Jul 6, 2007
2
US
Hi I am trying to convert a date stored as number (20060731) to datetime value in SAS.

So far I have tried - SLFDATE is a db field with a numeric value, representing date:

input(put(SLFDATE,8.),yymmdd8.)
AS FCSTDATE length=8


Thank you for your help.
 
Dates in SAS are numeric. Meaning that they are in fact the number of days (in case of a date value) or seconds (in case of a datetime value) from jan 1 1960. By you description, that the field (SLFDATE) is a numeric field, perhaps that field holds the correct date value but has some kind of display format.

Let us know what you find.
FYI,
If you get the number of days from 1/1/1960 (meaning that your var has the SAS date) all you need to do to get the datetime value is to multiply the date value by 86400 (number of seconds in a day). This will give you a proper SAS datatime value.
Klaz
 
Thank you for your reply!
My problem is a little bit different.
SLFDATE is a numeric field of an Oracle database. For some reasons developers decided to store Dates as numeric values. I need to transfer data from this Database to a MSSQL Database to a table with DateTime field.
My solution.
I broke down SLFDATE on three parts and insert "/" between them. So 20060731 became 07/31/2006. After that I transfer it to a temporary table as a string. MSSQL Table recognizes strings like that as a date value. After that using predefined View which converts this value to datetime format I transfered data from a temporary table to my final destination table.

It worked, but it's got to be a better way to do it :)))

Thank you again for your respond.
 
you might be able to use this...
Code:
  sasdate = input(slfdate,yymmdd8.);

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top