08-25-2016 04:49 PM - edited 08-26-2016 08:44 AM
I currently have a table that has dates as a datetime fromat (example: 02FEB2015:00:00:00.000). I am trying to firgure out how I can convert this column into a string so it matches up with another table with there date fromat as 2015-02-01 (as a string). I know there is the CAT funtcion but I do not know how to only select parts of the DAte time format to create the date string.
I have tried converting it in a query builder with the following steps ( look at attchement for screenshots)
1.I put the datetime column in the select data field
4. selected the format that matched the other field.
once i did this the dates were no longer the same then what they were . The year was showin 1900 when all the years are 2015 etc.
What would be the best way to get it in sring fromat by YYYY-MM-DD?
then selected the datetime column and selected properies
08-25-2016 07:06 PM
Working with DATES, DATETIMES and Times you need to know what is actually stored. DATES store numbers of Days, Datetimes numbers of seconds (both base with Jan 1, 1960 in SAS) and TIME is number of seconds since midnight.
When you say year looked like 1900 it makes me suspect that you were using Excel as that program uses a different base date (1 Jan 1900).
In either case changing the format does not change the underlying value. So a date expressed as a datetime will often be the base date or one day from it.
08-26-2016 02:22 AM
First, don't post example data or anything else in a Microsoft Office document. Nobody in his right mind opens such a file from the web, and the organizations that most people here work in have explicit provisions against it.
Post a screenshot image if necessary, but provide data in a textual format or even better in a data step that reads data from a cards; block.
To convert your SAS datetime value to the required string in a data step, use
newvar = put(datepart(oldvar),yymmddd10.);