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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 955 views
  • 2 likes
  • 3 in conversation