BookmarkSubscribeRSS Feed
vomer
Obsidian | Level 7

Hi there,

Just wondering how I can alter the following query to show date in the format I want.

Existing Date format: 15MAR2011:09:05:16.000000

Format I want: 15MAR2011:09:05:16

Query I am using:

proc sql;

create table data.test as

select       * from connection to odbc

(

select     ID,

             DATE AS CREATION_DATE,

from         maintable

);

quit;

5 REPLIES 5
Reeza
Super User

You need to add the format in to the date variable, you can do it in the same step or in a different step.

proc sql;

create table data.test as

select       ID, creation_date format=date20. from connection to odbc

(

select     ID,

             DATE AS CREATION_DATE,

from         maintable

);

quit;

sassharp
Calcite | Level 5

proc sql;

create table data.test as

select       * from connection to odbc

(

select     ID,

             DATE AS CREATION_DATE format=date20.,

from         maintable

);

quit;

Reeza
Super User

Will that work within the connection to ODBC, I thought that had to be native SQL in that section?

Patrick
Opal | Level 21

As Reeza hints: you need native SQL code inside the pass-through section. But you can of course do the formatting on the SAS side.

The variable DATE seems to contain datetime values so you would need to use a datetime format.

proc sql;

create table data.test as

select   ID, DATE AS CREATION_DATE format=datetime21.

from connection to odbc

(

select     ID,

             DATE

from         maintable

);

quit;

PGStats
Opal | Level 21

Or, if you don't care/want the time information in creation_date :

proc sql;
create table data.test as
select     ID
          ,datepart(IMPORTED_DATETIME) as creation_date format=date20.
from connection to ODBC
     (

          select     ID
                    ,DATE AS IMPORTED_DATETIME
          from maintable
     );
quit;

PG

PG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1514 views
  • 0 likes
  • 5 in conversation