BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TheNovice
Quartz | Level 8

Hi all,

 

 I am fairly comfortable joining 2 tables in passthrough but have never done 3...

Tables are like this:

 

Table A 
IDDate
12328-May-20
45629-May-20
Table B  
prp_idprp_datePrP_SEQ_NO
12328_may-2080143418

 

Table c  
IDPrPI_SEQ_NOPrPI_AMOUNT
12380143418100
1238014341850
 
Output would be:
 
IDDatePRPsum_prp_amt
12328-May-20Y150
 
 
So A.id = b.id to get PrP_SEQ_NO
and then b.PrP_SEQ_NO = c.PrP_SEQ_NO to get amount which needs to be group by PrP_SEQ_NO
 
can all this be done in pass through? Table b and c reside on oracle database and table a is the base table that i need to join to.
 
i have joined A and B successfully but getting stumped on adding in C. Any direction is appreciated

proc sql;
CONNECT TO ORACLE AS ORADB (user=&NAME password=&pASS  path=ExaODIN preserve_comments);
create table Prp as
select  a.*,
CASE WHEN (B.prp_date) ^=. THEN 'Y' ELSE 'N' END AS PrP
from Abc a left join connection to ORADB
   
  (select prp_id,prp_date
     from ods.promise
     where prp_date >= '01APR2020' and prp_status <> 'C'
          ) b

  on  a.id= B.prp_id
  and a.Date = datepart(b.prp_Date)
  group by a.id

;  
Disconnect from ORADB;
quit; 
 
1 ACCEPTED SOLUTION

Accepted Solutions
smantha
Lapis Lazuli | Level 10
proc sql;
CONNECT TO ORACLE AS ORADB (user=&NAME password=&pASS  path=ExaODIN preserve_comments);
create table Prp as
select  a.*,
CASE WHEN (B.prp_date) ^=. THEN 'Y' ELSE 'N' END AS PrP
from Abc a left join connection to ORADB
   
  (select prp_id,prp_date,prpi_amount
     from (select * from ods.promise 
          where prp_date >= '01APR2020' and prp_status <> 'C' )a
      inner join
	  (select id, prpi_seq_no,sum(prPI_Amount) as prpi_amount from ods.table_C) c
	 on 
     a.prp_id=c.id
     and
	 a.PrP_SEQ_NO = c.PrP_SEQ_NO
       
          ) b

  on  a.id= B.prp_id
  and a.Date = datepart(b.prp_Date)
  group by a.id

;  
Disconnect from ORADB;
quit; 

View solution in original post

4 REPLIES 4
smantha
Lapis Lazuli | Level 10
proc sql;
CONNECT TO ORACLE AS ORADB (user=&NAME password=&pASS  path=ExaODIN preserve_comments);
create table Prp as
select  a.*,
CASE WHEN (B.prp_date) ^=. THEN 'Y' ELSE 'N' END AS PrP
from Abc a left join connection to ORADB
   
  (select prp_id,prp_date,prpi_amount
     from (select * from ods.promise 
          where prp_date >= '01APR2020' and prp_status <> 'C' )a
      inner join
	  (select id, prpi_seq_no,sum(prPI_Amount) as prpi_amount from ods.table_C) c
	 on 
     a.prp_id=c.id
     and
	 a.PrP_SEQ_NO = c.PrP_SEQ_NO
       
          ) b

  on  a.id= B.prp_id
  and a.Date = datepart(b.prp_Date)
  group by a.id

;  
Disconnect from ORADB;
quit; 
TheNovice
Quartz | Level 8

It worked. Thank you so much!!

mklangley
Lapis Lazuli | Level 10

Adding onto @smantha's solution, just include 

,b.prpi_amount as sum_prp_amt

in the first select statement.

TheNovice
Quartz | Level 8
I did, thank you very much

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 4 replies
  • 1661 views
  • 1 like
  • 3 in conversation