Programming the statistical procedures from SAS

Problem with Merge

Reply
Super Contributor
Posts: 1,040

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

data LOS_final_1 MORT_final_1 READMITS_final_1;

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

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

READMITS_ranks(in=e) READMITS_Percentiles(in=f);

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;

Grand Advisor
Posts: 10,062

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,040

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;

data READMITS_final_1;

merge READMITS_ranks(in=a) READMITS_Percentiles(in=b);

by Discharge_Quarter;

run;

Grand Advisor
Posts: 16,925

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.

Respected Advisor
Posts: 4,770

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,040

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.

Respected Advisor
Posts: 4,770

Re: Problem with Merge

Then this illustrates a good lesson.  While there are often many ways to achieve an acceptable solution in SAS, pick the right tool for the job.  If you do, your program will usually be short and simple.  If you pick the wrong tool for the job, your program will become complex and more difficult to work with.  Occasionally, a programming objective requires complexity.  (Unfortunately, if you hang out here you see a non-representative sample of more complex problems, not the simple ones.)  As a general rule, if your program is become complex, think about whether there is another way to get what you want.

Good luck.

Ask a Question
Discussion stats
  • 6 replies
  • 195 views
  • 0 likes
  • 4 in conversation