BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Datino
Obsidian | Level 7

Using Enterprise Guide.

When I run the attached code, I get the following (relevant snips) in the log:

 

 

24 create table test (valid_from datetime format=datetime20.);
________
1
WARNING 1-322: Assuming the symbol DATE was misspelled as datetime.

 

 

 

create table WORK.TEST( bufsize=8192 )
(
valid_from num format=DATETIME20. informat=DATE.
);

30 quit;

 

 

How do I create datetime columns?

 

proc sql;
	create table test (valid_from datetime format=datetime20.);
quit;


proc sql;
 describe table test;
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
collinelliot
Barite | Level 11

Just specify "num" instead of datetime. Datetime values are just numeric fields, so as long as you're populating the tables with valid SAS datetime values you should be fine.

View solution in original post

6 REPLIES 6
collinelliot
Barite | Level 11

Just specify "num" instead of datetime. Datetime values are just numeric fields, so as long as you're populating the tables with valid SAS datetime values you should be fine.

collinelliot
Barite | Level 11

e.g. 

proc sql;
	create table test (valid_from num format=datetime20.);
quit;

proc sql;
 describe table test;

 insert into test
 values('01JUN2015:00:12:00'dt);
quit;
Datino
Obsidian | Level 7

Thank you, I thought the logical thing would be to declare the type like one does with date columns, I was wrong.

Reeza
Super User

Dates are numbers too, not a type either.

Reeza
Super User

There is no datetime type in SAS, only numbers and characters. Change it to NUM and it works like a charm. 

Datetime is the number of seconds from Jan 1, 1960.

 

proc sql;
	create table test (valid_from num format=datetime20.);
quit;


proc sql;
 describe table test;
quit;
Tom
Super User Tom
Super User

A datetime value is stored in a numeric variable. Just use any of the aliases that PROC SQL accepts for a number.

Syntax error, expecting one of the following: 
CHAR, CHARACTER, DATE, DEC, DECIMAL, FLOAT, INT
, INTEGER, NUM, NUMERIC, REAL, SMALLINT, VARCHAR.

So anything except CHAR, CHARACTER or VARCHAR will work.

proc sql;
  create table test (valid_from real format=datetime20.);
  describe table test;
quit;

Or you could just create the table using a data step, no need to bother with SQL.

data test ;
  attrib valid_from format=datetime20.;
  stop;
run;
proc contents data=test;
run;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 3913 views
  • 1 like
  • 4 in conversation