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

Hi guys,

 

I'd like to create a table with a datetime column and then insert some random dates.

For example:

 

proc sql;
create table PALETA
(DATA_ID DATETIME);
insert into paleta (DATA_ID) values ('1Sep2015:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Oct2015:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Nov2015:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Dec2015:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Jan2016:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Feb2016:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Mar2016:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Apr2016:0:0:0'dt);
insert into paleta (DATA_ID) values ('1May2016:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Jun2016:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Jul2016:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Aug2016:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Sep2016:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Oct2016:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Nov2016:0:0:0'dt);
insert into paleta (DATA_ID) values ('1Dec2016:0:0:0'dt);
quit;

 

The issue is, I receive asterisk result instead of a datetime.

In order to make it work, I need to create another procedure:

 

proc sql;
create table Paleta2 as
SELECT DATA_ID FORMAT=DATETIME20.
from paleta;
quit;

 

Can you please help out how to make it in one procedure instead of adding the second one?

thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I assume this is not using a database, hence just adding format statement should do the trick:

proc sql;
  create table PALETA (DATA_ID DATETIME format=datetime20.);
  insert into paleta (DATA_ID) values ('1Sep2015:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Oct2015:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Nov2015:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Dec2015:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Jan2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Feb2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Mar2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Apr2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1May2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Jun2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Jul2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Aug2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Sep2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Oct2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Nov2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Dec2016:0:0:0'dt);
quit;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I assume this is not using a database, hence just adding format statement should do the trick:

proc sql;
  create table PALETA (DATA_ID DATETIME format=datetime20.);
  insert into paleta (DATA_ID) values ('1Sep2015:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Oct2015:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Nov2015:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Dec2015:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Jan2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Feb2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Mar2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Apr2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1May2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Jun2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Jul2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Aug2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Sep2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Oct2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Nov2016:0:0:0'dt);
  insert into paleta (DATA_ID) values ('1Dec2016:0:0:0'dt);
quit;
pkonopnicki
Obsidian | Level 7
Thanks a lot, I thought it will be that obvious 😛
Ksharp
Super User

proc sql;
create table PALETA
(DATA_ID NUM format=datetime.);
insert into paleta (DATA_ID) values ('1Sep2015:0:0:0'dt);

select * from paleta;
quit;

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
  • 3 replies
  • 20558 views
  • 1 like
  • 3 in conversation