- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I have below data
data have1;
input id;
datalines;
1287
1805
1881
1881
;
run;
data have2;
input id;
datalines;
1287
1805
1805
1805
1881
1892
1892
1892
;
run;
I want records, below are the conditions:
1. if have1 and have2 has same id then I want those records from have1.
2. if have1 has the id and have2 doesn't have it then we want it.
3. if have1 doesn't have the id and have2 has it then we want those records.
For example below:
data want;
input id;
datalines;
1287
1805
1881
1881
1892
1892
1892
;
run;
Thanks,
Adi
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Does this represent your actual data? Do you have only the ID variable in your data sets?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@chinna0369 wrote:
Hi all,
I have below data
data have1; input id; datalines; 1287 1805 1881 1881 ; run; data have2; input id; datalines; 1287 1805 1805 1805 1881 1892 1892 1892 ; run;
I want records, below are the conditions:
1. if have1 and have2 has same id then I want those records from have1.
2. if have1 has the id and have2 doesn't have it then we want it.
3. if have1 doesn't have the id and have2 has it then we want those records.
For example below:
data want; input id; datalines; 1287 1805 1881 1881 1892 1892 1892 ; run;
Thanks,
Adi
I am having a very hard time telling what you want and whether you want 1, 2 or 3 data sets.
Your current list of requirements basically says that you want everything, at least given the limited data.
This creates 3 datasets, each matching a different one of your requirements. Not: you did not provide data that has any records for the second requirement.
proc sort data=have1; by id; run; proc sort data=have2; by id; run; data want1 want2 want3 ; merge have1 (in=in1) have2 (in=in2) ;
by id; if in1 and in2 then output want1; if in1 and not in2 then output want2; if not in1 and in2 then output want3; run;
The IN= option creates a temporary variable that indicates whether the current record has a contribution from the given data set. This is a 1/0, i.e. true/false value, so can be used to perform conditional actions based on the status of the variable(s).