BookmarkSubscribeRSS Feed
harshpatel
Quartz | Level 8

Hi,

How to call a sql stored procedure into SAS Viya 3.5?

I am running below code but it is throwing error.

 

PROC SQL;
Connect to odbc (datasrc="****"
user ="*****" password = "*******" );
create table t as
select * from connection to odbc
Execute(dbo.stp) by odbc;
Disconnect from odbc;
QUIT;

 

Error:

(Execute(dbo.stp)) by odbc;
------- -
79 22
76
ERROR 79-322: Expecting a SELECT.
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, ), *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.
ERROR 76-322: Syntax error, statement will be ignored.

 

1 REPLY 1
jklaverstijn
Rhodochrosite | Level 12

Hi,

 

You are mixing up two SQL Pass-Through techniques: SELECT FROM and EXECUTE. Using EXECUTE is the correct way to call a stored procedure. But running a SELECT on top of that in a single query is syntactically unsupported. In fact you are mixing DDL and DML statements. Getting a result set with EXECUTE is not supported.

 

A work-around would be to have the STP create a result set and query that table after calling the STP, effectively splitting up the SELECT and EXECUTE statements.

 

Hope this helps,

-- Jan.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 650 views
  • 1 like
  • 2 in conversation