Desktop productivity for business analysts and programmers

How to convert datetime to string date in SAS Enterprise guide 6.1

Reply
New Contributor
Posts: 3

How to convert datetime to string date in SAS Enterprise guide 6.1

[ Edited ]

Hello 

 

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 

2.select properties

3. change

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 

Grand Advisor
Posts: 17,464

Re: How to convert datetime to string date in SAS Enterprise guide 6.1

DATEPART() -> Extract date portion

PUT() -> Convert to string

Grand Advisor
Posts: 10,251

Re: How to convert datetime to string date in SAS Enterprise guide 6.1

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.

 

 

Esteemed Advisor
Posts: 6,734

Re: How to convert datetime to string date in SAS Enterprise guide 6.1

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.);
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 3 replies
  • 2870 views
  • 0 likes
  • 4 in conversation