BookmarkSubscribeRSS Feed
Lauror
Calcite | Level 5

Hi SAS Community,

 

You've got a newbie in the building when it comes to SQL, so please be gentle as to date I have been using EG in anything I've been carrying out.  I've been told that I have a really simple piece of existing code that can just be ran without issue, but it's throwing up an error on step 1.

 

Error "Expression using equals (=) has components that are of different data types"

 

I've determined that the code is trying to pull in a numerical value against a left join that has a character value but I don't know how to write the code to change the numerical to character apart from thinking it needs to read something like gl_codes=put(account,8)

 

from INPUT_DATA as t1

left join gl_codes as t3
on t1.account =t3.gl_code

 

gl_codes is numeric

account is character (LENGTH8)

 

Thanks!

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Something like this:

on t1.account = put(t3.gl_code,8.)

 

--
Paige Miller
Kurt_Bremser
Super User

Follow Maxim 3 and get to know your data:

How many digits are stored in account? Are there leading zeroes? Are the values left- or right-aligned?

This will determine how you do the conversion of the numeric variable.

Astounding
PROC Star

Very likely, it would be simpler to (for comparison purposes) convert from character to numeric:

from INPUT_DATA as t1

left join gl_codes as t3
on input(t1.account, 12.) = t3.gl_code

Just pick a wide enough width ... this example assumes that ACCOUNT will be no longer than 12 characters.

DeJanae07
Calcite | Level 5
Hello,

If your goal is to convert a numeric variable to a character variable you must use the "PUT" function.
The PUT function is as follows:
new_variable = PUT (original_variable, format.);

If your goal is to convert a character variable to a numeric variable, you must then use the "INPUT" function,
The INPUT function is as follows:
new_variable = INPUT (original_variable, informat.);

I hope these two functions help with your future conversions of variables.

De'Janae'

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 9011 views
  • 1 like
  • 5 in conversation