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;
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;
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
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.