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

Hi! I am struggling with SAS syntax error diagnosis. I am new to SAS and I have been trying hard to resolve simple errors but I still cant. Any help with the below error from my proc procedure please.

 

proc sql;
    create table Co_STLoc as
    select a.*, b.St_fips AS Client_state, co_fips AS G132
    from Co_ST_Out as a left join Fipsmod1 as b
    on a.State = b.State AND a.county = b.county;

quit;

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Run a proc contents on each of your input data sets. Check your types fo the State & County variables between each data set. PUT() will convert a number to a character and INPUT() will convert a character to a number.

You can do the conversion in your ON clause directly once you figure it out.

ie
If county was character in table B but numeric in table A this is what your ON should be:
a.county = input(b.county, 8.)

If county was numeric in table B and character in table A you could convert it to a character.
a.County = put(b.county, 8. -l);

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

In a.state=b.state, one data set has state as numeric and the other has state as character. Or, it applies to a.county = b.county.

 

So you have to have two character variables, or two numeric variables, surrounding the equal sign, for this to work.

--
Paige Miller
Reeza
Super User
Run a proc contents on each of your input data sets. Check your types fo the State & County variables between each data set. PUT() will convert a number to a character and INPUT() will convert a character to a number.

You can do the conversion in your ON clause directly once you figure it out.

ie
If county was character in table B but numeric in table A this is what your ON should be:
a.county = input(b.county, 8.)

If county was numeric in table B and character in table A you could convert it to a character.
a.County = put(b.county, 8. -l);
adzoyi
Calcite | Level 5
I appreciate the help.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 717 views
  • 1 like
  • 3 in conversation