BookmarkSubscribeRSS Feed
nupedoc79
Fluorite | Level 6

I know how to access SQL server via SAS Access / Pass Through Connection to read SQL server database tables. I would like to know, is there a way to execute a SAS program via a SQL Server Management Studio script or store procedure?

 

I've written a SAS Logger / Adapter program which executes several SAS programs then reporting if the programs contained errors. 

 

My Vice-President however would like SQL Server management Studio to execute the SAS Logger / Adapter program. I'm looking for SAS code examples or documentation. 

 

Thanks, 

3 REPLIES 3
Quentin
Super User

Where is your SAS code executing (on a server?  on a PC?)

 

If your SSMS job is running somewhere that can see your SAS environment, it's possible you could do it with the SQL server equivalent of the SAS X command to execute the .sas file as a batch job.

 

Looks like xp_cmdshell might be the equivalent of X:

 

USE master;  
  
EXEC xp_cmdshell 'copy c:\SQLbcks\AdvWorks.bck  
    \\server2\backups\SQLbcks', NO_OUTPUT;  
GO  

https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/xp-cmdshell-tran...

 

But it seems a bit hokey to have SSMS starting a SAS job.  It might be better to look into scheduling options for the SAS job.  Or even scheduling options for running the SQL job and then running the SAS job.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
nupedoc79
Fluorite | Level 6
SAS program is running on a server. Your last two statements are on point and are what I advised my VP we should do.

Thanks for you
SASKiwi
PROC Star

SSMS is a tool for interacting with SQL Server databases. Why would you use it for running SAS jobs? It really is the wrong tool for the job.

 

I see no advantages in attempting this, only complications. I personally use SSMS for developing SQL that can then be dropped into SAS SQL Passthrough queries, but I do that part in SAS Enterprise Guide.

 

You still have to develop your SAS jobs accessing SQL server in a SAS IDE like SAS Enterprise Guide or SAS Studio so why not also run them from there? If you need to run SAS batch jobs, then SAS Management Console is the best tool for the job IMHO.  

 

 

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
  • 3 replies
  • 1351 views
  • 1 like
  • 3 in conversation