BookmarkSubscribeRSS Feed
MILKYLOVE
Calcite | Level 5

Hello,

 

I have two tables with identical columns A, B, C, D, E, F.

T1 has 2000 values 

T2 has 5300 values

These two tables have 4 primary keys: A,C,D,F.

 

So I want to create a new table and take values from T2 where A,C,D,F are not present in T1. 

 

How do I proceed please?

 

I have tried proc sql 'except', but it is comparing all columns in both tables 

3 REPLIES 3
yabwon
Amethyst | Level 16
data T1 T2;
input A B C D E F;
if mod(_N_,2) then output T1;
output T2;
cards;
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 7 8
4 5 6 7 8 9
5 6 7 8 9 0
;
run;


proc sql;
select A,C,D,F from T2
except
select A,C,D,F from T1
;
quit;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



MILKYLOVE
Calcite | Level 5

Hi,

 

I need all the columns A,B,C,D,E,F in the output table. But I need to compare only the four primary keys A,C,D,F.

yabwon
Amethyst | Level 16
proc sql;
select * from T2
natural inner join
(
select A,C,D,F from T2
except
select A,C,D,F from T1
)
;
quit;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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
  • 958 views
  • 0 likes
  • 2 in conversation