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.

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
VS
Calcite | Level 5 VS
Calcite | Level 5

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


sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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