BookmarkSubscribeRSS Feed
SASAna
Quartz | Level 8

 

Hello SAS Users,

 

I wanted some help to clear this error.

 

I am merging SAS dataset leftouter join to ORacle table (many to one join), I am getting the dates error. How to resolve this?

 

PAID_DT variable is DATE format in oracle table.

 

 

Libname test oracle     user = &MyId orapw=&mypwd  path = "&Mydb" schema = Test  Oracle_73 = NO;

 

proc sql;

create table select a.* ,  case when b.CLM_ID is null then '0' else '1' end as test_case

from output_all  a left outer join
                         test.sum_oracle_table (DBKEY=CLM_ID  DBSASTYPE=(PAID_DT=DATE)) b
            on put(datepart(b.PAID_DT),yymmddd10.) between '2017-10-01' and '2018-03-31'
            and a.clm_id = b.clm_id
                  ;
ERROR: Error fetching from cursor. ORACLE error is ORA-01843: not a valid month.

3 REPLIES 3
PGStats
Opal | Level 21

I guess if you ask for DBSASTYPE=(PAID_DT=DATE), you don't need to use datepart() on paid_dt.

PG
RW9
Diamond | Level 26 RW9
Diamond | Level 26

There are several errors and bad coding here before even looking at the code, create table with nothing stipulated, not finished block, upper case coding etc. all of which combine to make the code next to impossible to read.  So:

 

proc sql;
  create table want as 
  select  a.*,  
          case when b.clm_id is null then '0' 
               else '1' end as test_case
  from    output_all a 
  left outer join test.sum_oracle_table (dbkey=clm_id  dbsastype=paid_dt=date)) b
  on      put(datepart(b.paid_dt),yymmddd10.) between '2017-10-01' and '2018-03-31'
  and     a.clm_id=b.clm_id;
quit;

Now obviously as you have not provided and test data in the form of a datastep, or shown what the data is its hard to guess, but I would say you either have the put() date wrong or the between two text strings (it depends on where the code is executed).  I would suggest that:

  on      b.paid_dt between '01OCT2017'd and '31MAR2018'd

Would be more appropriate, however I cannot try it.

 

Kurt_Bremser
Super User

paid_dt is already a date (per your dbsastype= option), so you must not use datepart() on it.

If paid_dt is a datetime value in Oracle, use dbsastype=(paid_dt=datetime).

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1352 views
  • 0 likes
  • 4 in conversation