Help using Base SAS procedures

-merge- error message

Reply
Occasional Contributor VS
Occasional Contributor
Posts: 15

-merge- error message

Hi,

I am trying to merge two files on DRG variable, which is character in both files (it includes numbers and letters).

But i get an error message:

31         data allmatched5 ;

32         merge allmatched4 (in=dat) HIP.DRG (in=drg);

ERROR: Variable drg has been defined as both character and numeric.

ERROR: Variable drg has been defined as both character and numeric.

 

I've tried to 're-build' DRG to see what will happen, but the message persists.

I would be very grateful if anyone has any ideas/suggestions how to deal with this issue.

Thanks

Victoria 

DATA HIP.DRG (DROP = DRG RENAME = (TEMP = DRG));

SET HIP.DRG;

TEMP = PUT(DRG, 4.);

RUN;

DATA allmatched4 (DROP = DRG RENAME = (TEMP = DRG));

SET allmatched4;

TEMP = PUT(DRG, 4.);

RUN;

PROC SORT DATA=allmatched4;

      BY DRG;

RUN;

PROC SORT DATA=HIP.DRG;

      BY DRG;

RUN;

DATA allmatched5 ;

MERGE allmatched4 (in=dat) HIP.DRG (in=drg);

      by DRG;

      if (dat) then         merge = 1;

      if (drg) then         merge = 2;

      if (drg and dat) then merge = 3;

RUN;

Super User
Posts: 5,516

Re: -merge- error message

DRG is a character variable in your data set.  You can't also use it as an IN= variable, which would be numeric.  Just change the name of the IN= variable from DRG to anything else that isn't already in use.

PROC Star
Posts: 1,324

Re: -merge- error message

Hi,

Your datasets allmatched4 and HIP.DRG both have a character variable named drg in them, right?

When you code in=drg as below:

 merge allmatched4 (in=dat) HIP.DRG (in=drg);

You are asking  SAS to create a numeric variable named drg which will be 1 if a record was read from HIP.DRG, else 0.

So because there is already a character variable named drg  in the program data vector, trying to create a numeric variable named drg causes the error.

If you change to in=indrg , your code should work.

HTH,

-Q.

Occasional Contributor VS
Occasional Contributor
Posts: 15

Re: -merge- error message

Thanks you both!!! For the solution and promptness!


Ask a Question
Discussion stats
  • 3 replies
  • 205 views
  • 0 likes
  • 3 in conversation