Hi, I'm trying to convert a "RefNumber," which is a char, into an integer inside a Proc SQL statement. Is that possible? I am getting an error when I run the code below.
Proc SQL;
Create Table Temp as
Select a.*,
cast(b.RefNumber as decimal(15,0)) as KeyRef
From TableA a
Left Join TableB b on a.KeyRef = b.KeyRef;
quit;
Error Message: ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, ),
From now on, when you get an error in the log, show us the ENTIRE log for that PROC or DATA step. DO not show us small portions of the log, we need to see the ENTIRE log for that PROC or DATA step.
Proc SQL;
Create Table Temp as
Select a.*,
b.KeyRef as keyref2
From TableA a
Left Join TableB b on put(a.KeyRef,15.0) = b.KeyRef;
quit;
Why? If you aren't doing calculations on RefNumber leave it as character. Also CAST is not a valid function in SAS SQL. CAST is a function used in some external DBMS SQL implementations like Oracle.
@ChickenLittle wrote:
Hi, I need it to be a numeric value because the RefNumber in the other table is numeric.
Actually this is backwards. You need to convert the numeric version in the other table to character.
From now on, when you get an error in the log, show us the ENTIRE log for that PROC or DATA step. DO not show us small portions of the log, we need to see the ENTIRE log for that PROC or DATA step.
Proc SQL;
Create Table Temp as
Select a.*,
b.KeyRef as keyref2
From TableA a
Left Join TableB b on put(a.KeyRef,15.0) = b.KeyRef;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: