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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

34 REPLIES 34
mohamed_zaki
Barite | Level 11

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

Armand
Calcite | Level 5

what do u mean by "equal two sides"?

thanks!

Astounding
PROC Star

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.

Armand
Calcite | Level 5

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!

Reeza
Super User

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?

Armand
Calcite | Level 5

it shows:

Client_id: Num

Client_name: CHAR

Score: Num

Status: CHAR

thanks!

Astounding
PROC Star

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?

Armand
Calcite | Level 5

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


Astounding
PROC Star

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. 

Armand
Calcite | Level 5


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.

Astounding
PROC Star

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.

Armand
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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