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.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: 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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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