In such cases the data sets still get merged but give missing values in the result.
There may be cases when some values of the common variable will not match between the data sets. Please note that the observations in both the datasets are already sorted in ID column. The above result is achieved by using the following code in which the common variable (ID) is used in the BY statement. The final data set will still have one observation per employee but it will contain both the salary and department variables. In this case to get the complete information for each employee we can merge these two data sets. ExampleĬonsider two SAS data sets one containing the employee ID with name and salary and another containing employee ID with employee ID and department. Let us understand data merging with the help of an example. The basic syntax for MERGE and BY statement in SAS is −įollowing is the description of the parameters used −ĭata-set1,Data-set2 are data set names written one after another.Ĭommon Variable is the variable based on whose matching values the data sets will be merged. input data sets must be sorted by the common variable(s) that will be used to merge on.input data sets must have at least one common variable to merge on.There are two Prerequisites for merging data sets given below − It is because the variables form both data sets get merged as one record based when there is a match in the value of the common variable. The total number of observations in the merged data set is often less than the sum of the number of observations in the original data sets. This is done using the MERGE statement and BY statement. Multiple SAS data sets can be merged based on a specific common variable to give a single data set.