Help using Base SAS procedures

Error persists: changing character to numeric

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

Error persists: changing character to numeric

Hi,

I am merging two datasets and one of them is in character format.

I applied few SAS procedures to change the character to number value before merging

but when I merge it still says 'Error: variable has been defined as both character and numeric'.

Here is what I tried, but with both of these I still get the error messages:

data temp1; set temp;

var1_n = var1*1;

var2_n=var2*1;

va3_n=var3*1;

run;

data temp1; set temp;

var1_n = input(var1, 3.);

var2_n = input (var2, 3.);

var3_n = input (var3, 3.);

run;

Any help and will be appreciated. Thanks


Accepted Solutions
Solution
‎09-05-2014 02:06 PM
Regular Contributor
Posts: 233

Re: Error persists: changing character to numeric

DATA HAVE;
INPUT ID $;
DATALINES;
1
2
3
4
;
RUN;

PROC CONTENTS DATA=HAVE; RUN;

DATA WANT;
SET HAVE;
ID_NEW=INPUT(ID,3.);
RUN;

PROC CONTENTS DATA=WANT; RUN;

Capture.JPG

View solution in original post


All Replies
Solution
‎09-05-2014 02:06 PM
Regular Contributor
Posts: 233

Re: Error persists: changing character to numeric

DATA HAVE;
INPUT ID $;
DATALINES;
1
2
3
4
;
RUN;

PROC CONTENTS DATA=HAVE; RUN;

DATA WANT;
SET HAVE;
ID_NEW=INPUT(ID,3.);
RUN;

PROC CONTENTS DATA=WANT; RUN;

Capture.JPG

Regular Contributor
Posts: 233

Re: Error persists: changing character to numeric

what are you trying to merge?

Contributor
Posts: 32

Re: Error persists: changing character to numeric

I am trying to merge two different datasets of chemicals that have numeric values. Both these datasets have a common variable lab_id.

Super User
Posts: 10,483

Re: Error persists: changing character to numeric

I think it is time to run proc contents on both temp and chemicals. Look for the same variable name but different data type. That would be your culprit(s).

Contributor
Posts: 32

Re: Error persists: changing character to numeric

Yes, running proc content helped in knowing the numeric and character variables. What was coming on the way of the merger was the persistence of the character variable after the new numeric variable were created. I dropped the character variables and that yielded to the merger.  Thanks

Super User
Posts: 10,483

Re: Error persists: changing character to numeric

You could also just rename them on the merge

data example

     merge set1 (rename=(var1=CharVar1))

          set2

;

run;

As an example if var1 was a variable with different types.

Contributor
Posts: 32

Re: Error persists: changing character to numeric

That is a good option. Thanks!

Super User
Posts: 10,483

Re: Error persists: changing character to numeric

If you have more than the three variables shown you may be having issues with one of them.

You don't show any merging code so it is a tad hard to give pointers where to look.

Contributor
Posts: 32

Re: Error persists: changing character to numeric

Thanks. Here is the merging code I used. Please note that the dataset 'chemicals' already has numerical values. Its only the dataset 'temp1' where values need to be converted to numeric.

data merged;

merge temp1 (in=x) chemicals;

by lab_id;

if x;

run;

☑ This topic is SOLVED.

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

Discussion stats
  • 9 replies
  • 315 views
  • 11 likes
  • 3 in conversation