Solved
Contributor
Posts: 21

# Variable has been defined as both character and numeric

I am trying to combine 8 datasets of different patient data captured in 6 month intervals in 2 different hospitals. So, I have to combine those 8 datasets so that I have one nice dataset that I could work on.

When I try to combine using

data Combined;  set fullextract1 fullextract2 fullextract3 fullextract4 fullextract5 fullextract6 fullextract7 fullextract8;

run;

I get multiple variables have been defined both as character and numeric like this:

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

So, I tried to put this in data statement for all involved variables in the individual datasets (basically trying to convert to character variables):

DOBch= put (DOB, \$7.);

drop DOB; rename DOBch=DOB;

But, still when finally try to combine using above combine statement, I still get these error statements. Please help.

Accepted Solutions
Solution
‎01-21-2013 09:14 PM
Esteemed Advisor
Posts: 5,398

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

Try to do your conversions this way :

data fullExtract1;

set fullExtract1(rename=(DOB=DOBnum));

DOB = put(DOBnum, 7.);

drop DOBnum;

run;

PG

PG

All Replies
Solution
‎01-21-2013 09:14 PM
Esteemed Advisor
Posts: 5,398

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

Try to do your conversions this way :

data fullExtract1;

set fullExtract1(rename=(DOB=DOBnum));

DOB = put(DOBnum, 7.);

drop DOBnum;

run;

PG

PG
Contributor
Posts: 21

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

Thanks a lot !!!!

It worked very well...Much appreciated..Venki

Regular Contributor
Posts: 202

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

Just so I'm clear...The guidance is to convert the variables in each individual dataset before joining, correct?

Esteemed Advisor
Posts: 5,398

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

You can convert as you join. RENAME the wrongly typed variables in the SET statement, convert them in the code, assign the result to the properly named variables, and drop the renamed variable. You can do for multiple datasets the same as I proposed in this old post for a single dataset

PG
Regular Contributor
Posts: 229

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

How would I combine two cases of your solution?

data nicholas._21305_21501 ;
set nicholas._21305_21501 (rename=(i1_Value=i1_Value_Character)) ;
i1_Value = put(i1_Value_Character, 1.) ;
drop i1_Value_Character ;
run ;

data nicholas._21305_21501 ;
set nicholas._21305_21501 (rename=(i2_Value=i2_Value_Character)) ;
i2_Value = put(i2_Value_Character, 1.) ;
drop i2_Value_Character ;
run ;

Esteemed Advisor
Posts: 5,398

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

Posted in reply to NicholasKormanik

data nicholas._21305_21501 ;
set nicholas._21305_21501 (rename=(i1_Value=i1_Value_Character i2_Value=i2_Value_Character)) ;
i1_Value = put(i1_Value_Character, 1.) ;

i2_Value = put(i2_Value_Character, 1.) ;
drop i1_Value_Character i2_Value_Character ;
run ;

and so on, for all wrong typed variables.

PG
Contributor
Posts: 32

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

I had the same problem, but when I do this, in my final table there are no values for "p_no". There is a column, but the values are missing.. What can I do about it? Something with the ''7.''? What does that mean?

``````DATA fullExtract1 (rename=(respno=p_nonum));
SET fullExtract1;
p_no = put(p_nonum, 7.);
DROP p_nonum;
RUN;``````

Esteemed Advisor
Posts: 5,398

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

Start a new forum topic, post the log and an example of the value of respno.

PG
☑ This topic is solved.

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

Discussion stats
• 8 replies
• 30533 views
• 0 likes
• 5 in conversation