BookmarkSubscribeRSS Feed
Ashpak
Calcite | Level 5

I have some complex sql code  to run from SAS, currently its working in SQL server but not from SAS. I tried simple SELECT SQL to execute from PROC sql with Execute odbc. its not giving any error and warning and no output

do you suggest what could be the problem

 

Proc SQL;

connect to odbc(DSN=&DSN user=&user password=&pwds);

Execute (DECLARE @Query NVARCHAR(MAX) = ''

Set @Query='select distinct qrm_db from [FASTControl].[dbo].ALM_NVPData

PRINT @Query

sp_executesql @Query

') by odbc;

quit;

 

 

NOTE: Writing HTML(EGHTML) Body file: EGHTML

23 FILENAME EGXLSSX TEMP;

24 ODS EXCEL(ID=EGXLSSX) FILE=EGXLSSX STYLE=Excel

25 OPTIONS (

26 EMBEDDED_TITLES="no" EMBEDDED_FOOTNOTES="no"

27 );

28

29 GOPTIONS ACCESSIBLE;

30 Proc SQL;

31 connect to odbc(DSN=&DSN user=&user password=&pwds);

32 Execute (DECLARE @Query NVARCHAR(MAX) = ''

33 Set @Query='select distinct qrm_db from [FASTControl].[dbo].ALM_NVPData

34 PRINT @Query

35 sp_executesql @Query

36 ') by odbc;

37 quit;

NOTE: PROCEDURE SQL used (Total process time):

real time 0.12 seconds

cpu time 0.05 seconds

 

1 REPLY 1
SASKiwi
PROC Star

Looks like it is working OK then. The SAS EXECUTE statement runs SQL but doesn't produce any result set. If you want to see a result set then you need to get the stored procedure to create a temporary SQL Server table, then query the temporary table in a following SQL SELECT query. 

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 823 views
  • 0 likes
  • 2 in conversation