BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ChickenLittle
Obsidian | Level 7

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: !, !!, &, ),

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

 

 

--
Paige Miller

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

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
Obsidian | Level 7
Hi, I need it to be a numeric value because the RefNumber in the other table is numeric.
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
ChickenLittle
Obsidian | Level 7
Yup, I got that part, I just needed the "input(...)" statement to realize what I needed, thanks so much!
PaigeMiller
Diamond | Level 26

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;

 

 

--
Paige Miller
ChickenLittle
Obsidian | Level 7
Thanks so much!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 6 replies
  • 2469 views
  • 2 likes
  • 3 in conversation