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;
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.
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.
Thanks you both!!! For the solution and promptness!
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.
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.