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!
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;
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;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.