BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LaiQ
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Filipvdr
Pyrite | Level 9
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

6 REPLIES 6
Filipvdr
Pyrite | Level 9
Do you have columns in match or tomatch where a/b is a variable? Try to rename in=a and in=b then.
LaiQ
Calcite | Level 5

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!

pearsoninst
Pyrite | Level 9

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;

LaiQ
Calcite | Level 5
Sorry, I have variables that are a and b. Hence I'm not able to merge. Will check properly next time.
Reeza
Super User

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. 

LaiQ
Calcite | Level 5
Sorry, found my error. Will check next time before posting. Thank you for your help anyway!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 4509 views
  • 0 likes
  • 4 in conversation