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;
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: