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.;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 11701 views
  • 3 likes
  • 3 in conversation