help on procsort and merge

Posts: 0

help on procsort and merge

I am trying to merge three datasets with inequal no of observations. Dataset A has 10 observations, Dataset B has 15 observations and dataset C has 3 observations. The objective of merging is to have a final dataset with a variable present in dataset C and it should have all the variables present in A.

Note: There are no common variables in dataset A and C.

I first sort dataset A and B with the common variable and merge them using the same common variable. The resultant dataset D is sorted by the same variable as in dataset C and are merged using the common variable.

After the merge the final dataset has blank obs in it and also when I am trying to sort the final data set using the same variable. It is giving me an error saying that there is an error in the sorting variable.

Please can you let me know what is wrong here?

Frequent Contributor
Posts: 95

Re: help on procsort and merge

Have you tried this:

data X;
merge D (in=a) C (in=b);
by common_var;
if b;

The "if b" should return only records where C has a record.

I've also found good success with PROC SQL and the LEFT JOIN / RIGHT JOIN / FULL JOIN functionality. I seem to recall that the way a DATA step and SQL merge is different, so sometimes one might be better suited to your application.
Post a Question
Discussion Stats
  • 1 reply
  • 2 in conversation