## Problem with Merge

Super Contributor
Posts: 1,041

# Problem with Merge

When I do this step i am not getting a and b merged instead the info available in other dataset also appears . Likewise with c and d  and e and f also..........!!!!Can somebody help me?

Thanks

mergeLOS_ranks(in=a) LOS_Percentiles(in=b)

MORT_ranks(in=c) MORT_Percentiles(in=d)

byDischarge_Quarter;

if a and b then output LOS_final_1;

if c and d then output MORT_final_1;

if e and f then output READMITS_final_1;

run;

Super User
Posts: 11,752

## Re: Problem with Merge

You will need to add either a KEEP= or DROP= option to the output data sets to get the variables you want. The choice would depend on which creates a longer list. It might look something like this

data LOS_final_1 ( keep = Discharge_Quarter var1 var2)

MORT_final_1 ( drop = var5-var15)

READMITS_final_1 (keep = list of variable names you want);

Super Contributor
Posts: 1,041

## Re: Problem with Merge

The variablke names are different for each of these datasets except for only 2 variable names which are common to all the rank datasets.

the variable names for the percentiles dataset are different.

BASICALLY I DINT WANT TO DO THIS STEP:

data
LOS_final_1;

merge LOS_ranks(in=a) LOS_Percentiles(in=b);

by Discharge_Quarter;

run;

data MORT_final_1;

merge MORT_ranks(in=a) MORT_Percentiles(in=b);

by
Discharge_Quarter;

run;

by Discharge_Quarter;

run;

Super User
Posts: 20,671

## Re: Problem with Merge

Then you need to rename your variables because if you merge with the same variable names they will overwrite each other.

Super User
Posts: 5,699

## Re: Problem with Merge

Why would you not use 3 DATA steps, each with its own MERGE?  That program does exactly what you need.  What is the reason for trying to switch?

Super Contributor
Posts: 1,041

## Re: Problem with Merge

Thats a good question. That works perfectly fine. But since i am a beginner in using sas programming i am trying to learn all the possible ways.

Super User
Posts: 5,699