Hi All,
I have two datasets (A and B) with the same variable names ID, Test 1, Test2.
I want to merge A and B but if A and B have the same ID, than use records in A, not in B.
I tried to use left join, seems not correct. Any cues?
Thanks,
data a; input ID test1 test2; datalines; 123 33 55 372 23 48 763 13 85 ; data b; input ID test1 test2; datalines; 568 41 36 587 23 48 763 25 69 ;
Please post sample data in the form of a data step
You're leaving out many important details.
Does an ID ever appear more than once in the same data set?
If an ID appears in B but not in A, do you still want to keep that ID?
If an ID appears in both data sets A and B, but TEST1 and TEST2 have missing values in A, do you want to use the values in B?
Do your actual data sets really contain just 3 variables, or do they contain many more than 3?
In all likelihood, the programming will be simple. The difficult part is figuring out what the results should be.
Thanks for the answer, I've provide a sample data.
@echoli wrote:
Thanks for the answer, I've provide a sample data.
There's no data in the post?
data a; input ID test1 test2; datalines; 123 33 55 372 23 48 763 13 85 ; data b; input ID test1 test2; datalines; 568 41 36 587 23 48 763 25 69 ;
can you see it now?
If the ID is not duplicated in either set then this may do what you want;
/* data step merge by requires sorted data*/ proc sort data=a; by id; run; proc sort data=b; by id; run; data want; merge b a; by id; run;
Sorts included even though example data already sorted just in case.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.