11-06-2013 07:17 AM
I have 4 datasets with a variable known as ID in them all.
The ID in one dataset can be present in the other 3 too.
I would like to do the following;
- get the unique list of ID's from each dataset
- output the unique list from each data set into a final dataset called "unique ID"which has the combined unique list.
I know I can do this in a set of datasteps, but is there a macro to do this?
11-06-2013 09:03 AM
I don't know of a SAS macro that does what you're asking, but the following (untested) macros might help:
proc sort data=&inds(keep=id)
%get_ids(set_a2 set_b2 set_c2 set_d2);
11-06-2013 10:59 AM
Like your approach Tom!
%macro test (set1,set2,set3,set4) ;
proc sort data=&set1; by id;run;
proc sort data=&set2; by id;run;
proc sort data=&set3; by id;run;
proc sort data=&set4; by id;run;
data want ;
set &set1 &set2 &set3 &set4;
11-06-2013 12:17 PM
Thank you guys, this was really very helpful, and the unique list generated really helped me do some other tasks that I needed too.
I was able to work with your suggestion, run through 12 datasets (each dataset is a month of a year) and extract a list of unique IDs.
I now have a list if ID's of people who been present at least once in the dataset,
The next step is this:
Sometimes the ID is present twice or 10 times in a dataset.
I want now to get a one-to-many match for my unique id through all the datatsets.
Here's an example:
Unique ID List jan feb
------------------ --------- ------------
ab ab ef
cd ab ef
ef gh ef
gh gh ef
I want the output to be;
ID Month & other variables etc...
11-07-2013 01:44 PM
How about the following:
/* if month ne ''; /* uncomment if you only want to see matches */
If order matters then you can sort the output by month and id.