Hi all,
I am fairly comfortable joining 2 tables in passthrough but have never done 3...
Tables are like this:
| Table A | |
| ID | Date |
| 123 | 28-May-20 |
| 456 | 29-May-20 |
| Table B | ||
| prp_id | prp_date | PrP_SEQ_NO |
| 123 | 28_may-20 | 80143418 |
| Table c | ||
| ID | PrPI_SEQ_NO | PrPI_AMOUNT |
| 123 | 80143418 | 100 |
| 123 | 80143418 | 50 |
| ID | Date | PRP | sum_prp_amt |
| 123 | 28-May-20 | Y | 150 |
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;
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;
It worked. Thank you so much!!
Adding onto @smantha's solution, just include
,b.prpi_amount as sum_prp_amt
in the first select statement.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.