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?
A little too much switching around regarding which data set is which. Try:
on a.Client_id = input(b.Client_id,6.);
You need the equal two sides to have compatible data type, you can use PUT to convert to character.
what do u mean by "equal two sides"?
thanks!
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.
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!
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?
both reports show Status as CHAR.
And Client_ID?
it shows:
Client_id: Num
Client_name: CHAR
Score: Num
Status: CHAR
thanks!
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?
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
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.
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.
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.
yep that s correct! the correct PROC CONTENTS is above.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.