BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
David_Billa
Rhodochrosite | Level 12

I would like to how to create a temp table in SQL Server by reading data from SAS work table via SAS explicit pass through

 

May I know what is the isue with INTO and FROM  in code below?

 

Proc sql noprint;
    Connect to SQLSVR (DATAsrc=&DATA. AUTHDOMAIN="XXXXX." dbMax_text=32767);
    Execute( 
        Select * 
             1 as Version
            ,1 as delivery
            ,'' as data
            ,'' as Location
            ,'MASTER' as tableName
            ,Count(*) as numberOfRecords                          
            into: #temp%trim(&unique_num.)                   

        From &_INPUT.
            Group by Version,data,location;
    ) by SQLSVR;
    Disconnect from SQLSVR;
Quit;

Error:

 

ERROR: CLI execute error: [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Incorrect syntax near ':'. : [SAS][ODBC 
       SQL Server Wire Protocol driver][Microsoft SQL Server]Executing SQL directly; no cursor.

 Any help to resolve the error?

1 ACCEPTED SOLUTION
7 REPLIES 7
SASKiwi
PROC Star

If &_INPUT refers to a SAS WORK table then your program won't work. Any SQL running inside an EXECUTE statement runs entirely on SQL Server and it knows nothing about SAS tables. Creating SQL Server temporary tables is best done using a SAS LIBNAME using the SQLSRVR engine. This post shows one way:

https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-to-populate-temp-table-with-SAS-dataset/td-p/...

 

This doc describes the general approach: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/n0irpkyp22l7vzn1il9lx6f4wmx9.htm

 

David_Billa
Rhodochrosite | Level 12
How to create a temp table in SQL Server using explicit pass through ?
David_Billa
Rhodochrosite | Level 12

@SASKiwi @Sajid01 Can't we create a temp table in SQL Server from SAS work table via SAS explicit pass through instead of using libname?

SASKiwi
PROC Star

@David_Billa  - Not possible unless your SAS program generates a bunch of SQL insert statements, one for each row you want to add - it's not a sensible solution. Using a LIBNAME statement and a PROC APPEND or SAS SQL is far preferrable.

David_Billa
Rhodochrosite | Level 12
Any examples to do it using SAS SQL as you mentioned?

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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