Desktop productivity for business analysts and programmers

Error: Variable has been defined as both character and numeric

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 94
Accepted Solution

Error: Variable has been defined as both character and numeric

Here is my code:

data libname.file_combined;

set libname.file_a

libname.file_b;

run;

I tried to merge two files and got this error:

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

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

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

Variables X, Y and Z has cells that are either numeric or alpha-numeric.  So my assumption is that I have to convert them to character.  I ran this code I got an error:  EXPECTING a FORMAT NAME.  It looks like SAS doesn't like the 5.

data file_a (drop=a_variablex);

set file_a (rename=(variablex=a_variablex));

variablex=input(a_variablex,5);

run;

Any advice/help is appreciated!

Thanks!


Accepted Solutions
Solution
‎01-16-2013 10:22 AM
Grand Advisor
Posts: 10,211

Re: Error: Variable has been defined as both character and numeric

When using a Format you need to have a period at the end.

Try

variablex= input(a_variablex,f5.);

You may have done this already, but it may be a good idea to run Proc Compare to see which data set has the numeric and which has the character versions of the variables in question.

View solution in original post


All Replies
Solution
‎01-16-2013 10:22 AM
Grand Advisor
Posts: 10,211

Re: Error: Variable has been defined as both character and numeric

When using a Format you need to have a period at the end.

Try

variablex= input(a_variablex,f5.);

You may have done this already, but it may be a good idea to run Proc Compare to see which data set has the numeric and which has the character versions of the variables in question.

Frequent Contributor
Posts: 94

Re: Error: Variable has been defined as both character and numeric

I did a PROC COMPARE:  file_a = $5. (character) and file_b=BEST 12. (num)

I ran this code and still got the same error (Variable has been definted as both character and numeric).

data file_b (drop=a_variablex);

set file_b (rename=(variablex=a_variablex));

variablex=input(a_variablex,$5.);

run;

Thoughts???


Grand Advisor
Posts: 10,211

Re: Error: Variable has been defined as both character and numeric

I would confirm that variablex is now a character variable. I suspect not. If not, try using variablex = put(a_variablex,f5.);

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 3473 views
  • 0 likes
  • 2 in conversation