BookmarkSubscribeRSS Feed
aabbccwyt
Obsidian | Level 7

Hi, I'm trying to merge two datasets by the same variable AcctNums:

data NewAcctNum;
        set NewAcctNum;
	merge Location_Data Purchases;
	by AcctNums;
run;

And it gives me "Variable AcctNum has been defined as both character and numeric.". I have already changed the variable AcctNum to a Numeric variable so I have no idea what I have done wrong. Can someone help please? Thank you. (It was a 1-1 merging.)

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16

You cannot use the set statement in merge , try the below code

 

 

data NewAcctNum;
	merge Location_Data Purchases;
	by AcctNums;
run;
Thanks,
Jag
aabbccwyt
Obsidian | Level 7

Hi Jag. Thank you again. I tried it however it is giving me the same thing.

 112        /*Merge the two datasets*/
 113        data NewAcctNum;
 114        merge Location_Data Purchases;
 ERROR: Variable AcctNum has been defined as both character and numeric.
 115        by AcctNums;
 116        run;

I'm wondering if there is a way to specify whether it's character or numeric. 

Jagadishkatam
Amethyst | Level 16
Unless i see that data i may not provide the solution,but you should try and check if the variable in location_data or purchases dataset has the acctnum as character or numeric , it should be same in both the datasets.
Thanks,
Jag
andreas_lds
Jade | Level 19

@aabbccwyt wrote:

Hi Jag. Thank you again. I tried it however it is giving me the same thing.

 112        /*Merge the two datasets*/
 113        data NewAcctNum;
 114        merge Location_Data Purchases;
 ERROR: Variable AcctNum has been defined as both character and numeric.
 115        by AcctNums;
 116        run;

I'm wondering if there is a way to specify whether it's character or numeric. 


Such issues almost always arise when proc import is used for reading data. Using a data step is recommended to prevent such situations. So, if you can: fix the import. If you can't do that, you will have to process one of the datasets and convert the numeric version to char.

unison
Lapis Lazuli | Level 10

Does the error say “Acctnum...” or “Acctnums...”? Your merge step says Acctnums but the error you detail lists Acctnum.

 

be sure that you’re merging on the correct variable.

-unison

-unison

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 593 views
  • 2 likes
  • 4 in conversation