I have 2 datasets

I need help with SAS query

```
Table 1
ID      Prin    Int     Tot     TranType    TranDt
101     100     15      115     P           1/1/2021
101     100     15      115     P           1/1/2021
102     500     15      515     P           5/1/2021
103     300     15      315     P           6/1/2021
104     250     10      260     P           8/1/2021
105     350     10      360     P           9/1/2021
105     300     10      310     P           10/1/2021

```

```
Table 2
ID      Prin    Int     Tot     TranType    TranDt
101     100     15      115     R           1/15/2021
103     300     15      315     R           6/2/2021
105     350     10      360     R           9/5/2021
105     300     10      310     R           10/5/2021

```

Final Output

```
Table 3
ID      Prin    Int     Tot     TranType    TranDt     Cat
101     100     15      115     P           1/1/2021   Rev
101     100     15      115     P           1/1/2021   Good
102     500     15      515     P           5/1/2021   Good
103     300     15      315     P           6/1/2021   Rev
104     250     10      260     P           8/1/2021   Good
105     350     10      360     P           9/1/2021   Rev
105     300     10      310     P           10/1/2021  Rev

```

I need to combine table 1 and table 2 and if combination of (ID Prin Int Tot) and TranType= P
matches Table 2 (ID Prin Int Tot) and TranType= R then
mark that row as Rev but 2nd row if duplicate should be marked as Good.
Output is shown in Table 3.
TranDt of Table 2 is good as long as it is >= Table1.TranDt.

I would appreciate any help on this query.

I tried grouping but I can't make it work.