Hi! I am a new-ish SAS user. I am trying to do a one-to-many data merge with two files in my work folder. However, I keep getting this error:
ERROR: Variable Type has been defined as both character and numeric.
However, the varaibles are exactly the same:
Name: NUMBER
Length: 8
Format: Best12
Informat: 12
Type: Numeric
I have tried multiplying NUMBER by one to be sure it is numeric or to see if it needed a reset of sorts, but that did not work
my sas code is this:
/* Sorting data and merging */
proc sort data = A; by NUMBER;
run;
proc sort data = B; by NUMBER;
run;
/*One to many data merge - NUMBER is numeric */
data Merged_A_B;
merge A (in = aaa) B (in = bbb);
by NUMBER;
if aaa*bbb = 0 then delete;
run;
I am thinking it may be how I am merging and I have looked online for help but was not able to find it. Help with this would be much appreciated!
C
This message is actually very specific. There is no problem with the variable named NUMBER. Rather, you have a variable named TYPE that is numeric in one of the data sets and character in the other.
Post your log and a proc contents for both data sets.
Do you have any other variables that might have the same name in both data sets but different types?
This message is actually very specific. There is no problem with the variable named NUMBER. Rather, you have a variable named TYPE that is numeric in one of the data sets and character in the other.
Thank you! This was the issue. I was able to correct it and it runs perfectly. Thanks again!!
C
You could replace the whole thing wth a single proc SQL step :
proc sql;
create table Merged_A_B as
select A.number, A.type,
/* other variables from A. or from B. */
from A inner join B on A.number=B.number;
quit;
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.