help with :ERROR: Expression using equals (=) has components that are of different data types.

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

help with :ERROR: Expression using equals (=) has components that are of different data types.

Here is the code

proc sql;

create table work.test as

select a.Client_id, a.Client_name, a.Score, a.Status,

          b.Client_id, b.Client_name, b.Score, b.Status,

          (a.score-b.score) as Score_diff,

case when a.status=b.status then 'match' else 'no match' end as Status_test

from Client_Report2 a

left join Client_Report1 b on a.Client_id=b.Client_id;

quit;

The Status data type is mixed : numeric value, string,

Status field has :

50

>60

more than a year

8%

3y

when i run the code in bold i get this error: ERROR: Expression using equals (=) has components that are of different data types.

Any help, please?


Accepted Solutions
Solution
‎01-15-2015 04:54 PM
Super User
Posts: 5,513

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

A little too much switching around regarding which data set is which.  Try:

on a.Client_id = input(b.Client_id,6.);

View solution in original post


All Replies
Super Contributor
Posts: 490

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

You need the equal two sides to have compatible data type, you can use PUT to convert to character.

Contributor
Posts: 46

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

Posted in reply to mohamed_zaki

what do u mean by "equal two sides"?

thanks!

Super User
Posts: 5,513

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

There are two places where your code uses an equal sign:

a.status=b.status

a.Client_id=b.Client_id

One of these has a "type mismatch".  That means the variable you are processing is character in one incoming data set and numeric in the other incoming data set.  Once you discover which variable is causing the problem, we can talk about solutions.

Good luck.

Contributor
Posts: 46

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

Posted in reply to Astounding

the variable Status is the one causing the problem because it has mixed values such as :

50

>60

more than a year

8%

3y

thanks!

Super User
Posts: 19,832

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

Run a proc contents on both your data sets (Client_Report1, Client_Report2) and look at what types (numeric/character) are for the variable Status. Are they the same or different?

Contributor
Posts: 46

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

both reports show Status as CHAR.

Super User
Posts: 19,832

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

And Client_ID?

Contributor
Posts: 46

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

it shows:

Client_id: Num

Client_name: CHAR

Score: Num

Status: CHAR

thanks!

Super User
Posts: 5,513

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

Let me just confirm here.  Are you saying all of these are true:

a.Client_ID is numeric

b.Client_ID is numeric

a.status is character

b.status is character

And you are still getting that error message?

Contributor
Posts: 46

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

Posted in reply to Astounding

that s correct!

do you think the error has something to do with the fact that the same variable(Status) has mismatch type like this? :

50

>60

more than a year

8%

3y


Super User
Posts: 5,513

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

Armand,

Definitely not a result of a mix of:

50

>60

It's perfectly OK to store "50" as the value of a character field.  The field is still character, no matter what characters it contains.

The one piece of your output that is decidedly weird is the PROC CONTENTS results for Client_ID.  It is not possible to have a numeric variable with a format/informat of $6.  Numeric formats/informats should not have a dollar sign. 

Contributor
Posts: 46

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

Posted in reply to Astounding


you are perfectly right , here is how Proc content looks like:

Client_Report1:

                                TYPE          LEN    FORMAT    INFORMAT    LABEL

Client_id:                  Num             8                                                  imdb id          

Client_name:          CHAR            68          $68             $68            Client name

Score:                     Num              8                                                 Score

Status:                   CHAR             128         $128          $128          Status

Client_Report2

                              TYPE            LEN    FORMAT    INFORMAT    LABEL 

Client_id:                 CHAR             6           $6               $6               imdb id           

Client_name:          CHAR            68          $68             $68            Client name

Score:                     Num              8                                                 Score

Status:                   CHAR             128         $128          $128          Status

Client_id data type are different.

Super User
Posts: 5,513

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

Well, you changed the PROC CONTENTS output for Client_Report1, for Client_ID.

Is Client_ID character in Client_Report2?  That would explain the results you are getting.

Contributor
Posts: 46

Re: help with :ERROR: Expression using equals (=) has components that are of different data types.

Posted in reply to Astounding

yep that s correct! the correct PROC CONTENTS is above.

🔒 This topic is solved and locked.

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

Discussion stats
  • 34 replies
  • 15737 views
  • 4 likes
  • 7 in conversation