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
Onyx | Level 15
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
Onyx | Level 15
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



Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 277 views
  • 0 likes
  • 2 in conversation