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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

3 REPLIES 3
ballardw
Super User

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.

jen123
Fluorite | Level 6

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???


ballardw
Super User

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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