Help using Base SAS procedures

How to insert dates with proc sql insert into?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

How to insert dates with proc sql insert into?

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.


Accepted Solutions
Solution
‎01-17-2017 03:31 PM
Trusted Advisor
Posts: 1,349

Re: How to insert dates with proc sql insert into?

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

View solution in original post


All Replies
Trusted Advisor
Posts: 1,349

Re: How to insert dates with proc sql insert into?

Try next code:

 

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

'01jan2017'd

);

quit;

Occasional Contributor
Posts: 18

Re: How to insert dates with proc sql insert into?

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.

Solution
‎01-17-2017 03:31 PM
Trusted Advisor
Posts: 1,349

Re: How to insert dates with proc sql insert into?

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

Occasional Contributor
Posts: 18

Re: How to insert dates with proc sql insert into?

Thank you!
Super User
Posts: 10,460

Re: How to insert dates with proc sql insert into?

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

Trusted Advisor
Posts: 1,349

Re: How to insert dates with proc sql insert into?

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

 

     date_var = datepart(datetime_var);

     format date_var date9.;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 333 views
  • 2 likes
  • 3 in conversation