BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Madhav4114
Calcite | Level 5
Table 1.
Newkey period
1. 201701
2. 201701
3. 201701
1. 201801

Table 2
Newkey. Period
1. 201701
2. 201701
1. 201801

Compare two tables and find out accounts(newkey) which are unique or not present in another table on each period.
1 ACCEPTED SOLUTION

Accepted Solutions
MayurJadhav
Quartz | Level 8

You can try this and adjust the code according to your requirement. @Madhav4114 

 

data Table1;
	input Newkey period;
	datalines;
1 201701
2 201701
3 201701
1 201801
;

data Table2;
	input Newkey Period;
	datalines;
1 201701
2 201701
1 201801
;
run;

proc sort data=Table1;
	by Newkey;
run;

proc sort data=Table2;
	by Newkey;
run;

data in_Table1 in_Table2 in_Both;
	merge Table1(in=a) Table2(in=b);
	by Newkey;

	if a and not b then
		output in_Table1;

	if b and not a then
		output in_Table2;

	if a and b then
		output in_Both;
run;

proc print data=in_Table1;
proc print data=in_Table2;
proc print data=in_Both;
run;
Mayur Jadhav
BI Developer. Writer. Creative Educator.

SAS Blog → https://learnsascode.com
YouTube Channel: → https://www.youtube.com/@imayurj

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Try this

 

data Table1;
input Newkey period;
datalines;
1 201701
2 201701
3 201701
1 201801
;

data Table2;
input Newkey Period;
datalines;
1 201701
2 201701
1 201801
;

data notpresent;

   if _N_ = 1 then do;
      dcl hash h(dataset : 'Table2');
	  h.definekey('Newkey', 'period');
	  h.definedone();
   end;
   
   set Table1;
   
   if h.check();

run;
yabwon
Onyx | Level 15

1) what did you try so far? 

2) what is your expected result? 

3) if you wan us to solve your homework at least prepare test data in form we could use them (i.e., data step with datalines) 

 

Bart

_______________
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



Madhav4114
Calcite | Level 5
Tried with fuller outer join but unsuccessful with results
MayurJadhav
Quartz | Level 8

You can try this and adjust the code according to your requirement. @Madhav4114 

 

data Table1;
	input Newkey period;
	datalines;
1 201701
2 201701
3 201701
1 201801
;

data Table2;
	input Newkey Period;
	datalines;
1 201701
2 201701
1 201801
;
run;

proc sort data=Table1;
	by Newkey;
run;

proc sort data=Table2;
	by Newkey;
run;

data in_Table1 in_Table2 in_Both;
	merge Table1(in=a) Table2(in=b);
	by Newkey;

	if a and not b then
		output in_Table1;

	if b and not a then
		output in_Table2;

	if a and b then
		output in_Both;
run;

proc print data=in_Table1;
proc print data=in_Table2;
proc print data=in_Both;
run;
Mayur Jadhav
BI Developer. Writer. Creative Educator.

SAS Blog → https://learnsascode.com
YouTube Channel: → https://www.youtube.com/@imayurj
Madhav4114
Calcite | Level 5
@MayurJadhav solution looks fine but taking a lot of time to run
P.s dataset size more than 5gb

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