DATA Step, Macro, Functions and more

Variable has been defined as both character and numeric

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

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
Respected Advisor
Posts: 4,663

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

View solution in original post


All Replies
Solution
‎01-21-2013 09:14 PM
Respected Advisor
Posts: 4,663

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: 199

Re: Variable has been defined as both character and numeric

@PGStats 

 

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

Respected Advisor
Posts: 4,663

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: 212

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 ;

 

Respected Advisor
Posts: 4,663

Re: Variable has been defined as both character and numeric

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
☑ This topic is solved.

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

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