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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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