DATA Step, Macro, Functions and more

Error: Variable has been defined as both character and numeric

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

Error: Variable has been defined as both character and numeric

Hello guys,

 

I know this problem has been answered a couple of times. But I tried most of the solution but I'm still unable to merge them and it's quite frustrating... so hope that you guys can help me see what's the problem here:

 

The data MATCH has account ID (numerical) with other variables and TOMATCH has only account ID (numerical) and counts (numberical). Hence, I would like to merge the files so that my new data COMBINEFILES will have the account numbers and the counts.

 

data match;
set match(rename=(account=acc));
account=input(acc,f15.);
drop acc;
run;

data tomatch;
set tomatch (rename=(account=acc));
account=input(acc,f15.);
drop acc;
run;

data combinefiles;
merge match (in=a) tomatch (in=b);
by account;
if a;
run;

But the output is always:

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

Really appreciate if you guys can help me.


Accepted Solutions
Solution
‎04-27-2016 05:13 AM
Regular Contributor
Posts: 229

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

Do you have columns in match or tomatch where a/b is a variable? Try to rename in=a and in=b then.

View solution in original post


All Replies
Solution
‎04-27-2016 05:13 AM
Regular Contributor
Posts: 229

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

Do you have columns in match or tomatch where a/b is a variable? Try to rename in=a and in=b then.
Contributor
Posts: 31

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

Really sorry... I didn't check my variables properly as it's a huge dataset... 

I have a variable named a and b so that's why I am unable to merge.

But thank you once again! Will check more diligently next time!

Frequent Contributor
Posts: 108

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

data match1;
input Account;
datalines;
1
2
3
5
;
data tomatch1;
input Account;
datalines;
1
2
3
6
;


data match;
set match1(rename=(account=acc));
account= put(acc,15.);
drop acc;
run;

data tomatch;
set tomatch1 (rename=(account=acc));
account=put(acc,15.);
drop acc;
run;

data combinefiles;
merge match1 (in=a) tomatch1 (in=b);
by account;
if a;
run;

Contributor
Posts: 31

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

Sorry, I have variables that are a and b. Hence I'm not able to merge. Will check properly next time.
Super User
Posts: 17,832

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

Your error doesn't match your data description. 

 

Please post code and log if you need further assistance. 

 

@pearsoninst Is correct about checking your IN variables. 

Contributor
Posts: 31

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

Sorry, found my error. Will check next time before posting. Thank you for your help anyway!
☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 2099 views
  • 0 likes
  • 4 in conversation