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

Greetings,

 

I'm trying to manually create some rows in a table, with the insert to statement, coded looks like this:

 

proc sql;
insert into lib.table values(
'OPEN',
10001,
10041,
10004,
'13',
'ACT');

quit;

 

My question is, how do I insert a date such as (01JAN2017) so that it is a valid SAS date? 

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

for datetime use '01jan2017:00:00:00'dt 

View solution in original post

6 REPLIES 6
Shmuel
Garnet | Level 18

Try next code:

 

proc sql;
insert into lib.table values(
'OPEN',
10001,
10041,
10004,
'13',
'ACT',

'01jan2017'd

);

quit;

Datino
Obsidian | Level 7

Thank you for your help, Shmuel, the answer you provided is correct.

 

However, it made me figure out that the column I'm trying to fill is actually datetime with a format of DATETIME22.3

 

I tried adjusting your solution to '01jan2017'dttm but it did not work.

Shmuel
Garnet | Level 18

for datetime use '01jan2017:00:00:00'dt 

Datino
Obsidian | Level 7
Thank you!
ballardw
Super User

Please don't be a lazy programmer and name datetime values as dates. When crossing the boundary to SAS the values are quite different and functions/actions that will work on DATES will either fail or create very unexpected results when used with DATETIMES (and vice versa).

Shmuel
Garnet | Level 18

@Datino - if you decide to convert datetime to date use next code to do it:

 

     date_var = datepart(datetime_var);

     format date_var date9.;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 6 replies
  • 13261 views
  • 3 likes
  • 3 in conversation