BookmarkSubscribeRSS Feed
VS
Calcite | Level 5 VS
Calcite | Level 5

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;

3 REPLIES 3
Astounding
PROC Star

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.

Quentin
Super User

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.

VS
Calcite | Level 5 VS
Calcite | Level 5

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


hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1280 views
  • 0 likes
  • 3 in conversation