- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A little too much switching around regarding which data set is which. Try:
on a.Client_id = input(b.Client_id,6.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need the equal two sides to have compatible data type, you can use PUT to convert to character.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
what do u mean by "equal two sides"?
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
both reports show Status as CHAR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And Client_ID?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
it shows:
Client_id: Num
Client_name: CHAR
Score: Num
Status: CHAR
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
yep that s correct! the correct PROC CONTENTS is above.