Architecting, installing and maintaining your SAS environment

Trying to run SAS Program as a Windows Service

Reply
Occasional Contributor
Posts: 5

Trying to run SAS Program as a Windows Service

I want to run a SAS program as a windows service in Windows Server 2008 R2 on SAS 9.3.
I have written a sample SAS code that creates a data set test in C drive as follows:

libname path "C:\";

data path.test;
result = "Through service";
run;

 

Next, I'm trying to create a SAS Service using SAS Service Configuration Utility as per the following linkhttp://support.sas.com/documentation/cdl/en/hostwin/63047/HTML/default/viewer.htm#n11p2kzepqm4abn1f2.... Kindly refer to the attached screenshot for the parameters.

Below are the different variations that I have used as the service path:

1. "E:\SASHome\SASFoundation\9.3\sas.exe" -SYSIN "C:\MyPgm.sas"

2. "E:\SASHome\SASFoundation\9.3\sas.exe" -noterminal -SYSIN "C:\MyPgm.sas"

3. "E:\SASHome\SASFoundation\9.3\sas.exe" -noterminal -SYSIN "C:\MyPgm.sas" -config "E:\SASHome\SASFoundation\9.3\nls\en\SASV9.CFG"

 

In all the scenarios, I'm getting the following error:

 

"Windows could not start the SAS_service service on local computer.
Error 1067: The process terminated unexpectedly."

 

Any help in this regard would be highly appreciated.
Thanks


Error.jpg
Super User
Posts: 7,771

Re: Trying to run SAS Program as a Windows Service

Looks like the environment in which the Windows service runs can't see your network drive E:

Most probably because E: is mounted after you log on.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 5

Re: Trying to run SAS Program as a Windows Service

Posted in reply to KurtBremser

Actually, I had thought so and that's why I logged on to the server and tried to run the serevice manually. Still the same error.

Super User
Posts: 7,771

Re: Trying to run SAS Program as a Windows Service

Did you try

E:\SASHome\SASFoundation\9.3\sas.exe -SYSIN C:\MyPgm.sas

(no quotes needed, as there are no blanks in the file/pathnames) straight from the commandline? And what messages did you get?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 3,252

Re: Trying to run SAS Program as a Windows Service

Try running your test program as a batch job from a Windows command prompt. Does it work OK?

Occasional Contributor
Posts: 5

Re: Trying to run SAS Program as a Windows Service

[ Edited ]

@SASKiwi, I have tried what you have asked. It works as expected - creates a data set test at desired location. Refer to the attached screenshot for the same.

 

@KurtBremser, I have also tried what you have asked and it still didn't work. However, in the bat file created, I have not used quotes - you can refer to the screenshot, and it worked fine.


Error1.jpg
Super User
Posts: 7,771

Re: Trying to run SAS Program as a Windows Service

If SAS does not complain immediately, it has run the program. Look what's in C:\MyPgm.log.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 3,252

Re: Trying to run SAS Program as a Windows Service

[ Edited ]

Since your batch job test worked OK I think that confirms that you are invoking SAS correctly.

 

What happens if you add a statement using the SLEEP function to your test DATA step - telling your program to sleep for 5 minutes (RC = sleep(60 * 5); ). Does your Windows service continue OK for 5 minutes then stop or does it still stop immediately?  

Occasional Contributor
Posts: 5

Re: Trying to run SAS Program as a Windows Service

@KurtBremser, since service isn't getting started, SAS isn't even getting invoked - so no logs in this case.

@SASKiwi, I'd say my understanding here is that since SAS isn't even getting invoked, so introducing sleep or for that matter changing anything in the data step may not be helpful as my SAS code isn't even getting executed. I believe firstly, I need to be able to invoke SAS from Services.

Super User
Posts: 3,252

Re: Trying to run SAS Program as a Windows Service

What about your user account? Do you have appropriate admin rights to create a Windows service?

 

 

Super User
Posts: 7,771

Re: Trying to run SAS Program as a Windows Service


gurbeer wrote:

@KurtBremser, since service isn't getting started, SAS isn't even getting invoked - so no logs in this case.

 


I was not talking about what happens when you run it as a service, I was talking about running it from the commandline directly.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 5

Re: Trying to run SAS Program as a Windows Service

Posted in reply to KurtBremser

@SASKiwi, I'm not very sure about whether I have rights to start a service or not. I'm able to create one, so, I assumed I can simply start one too. But then, shouldn't that give an error saying something similar to rights required to start a service or something?

@KurtBremser, I was able to run it through commandline and generate a log file as attached, which says the data set created successfully.


Log.jpg
Super User
Posts: 7,771

Re: Trying to run SAS Program as a Windows Service

I just googled the 1067 error, and it seems to indicate that the service in question (SAS in your case) exited with an exit code <> 0.

My next tries would be

- write a simple .bat that echoes some text into c:\test.txt

- try to run that as a service

- if that works, add the SAS command line in the batch file, capture the exit code immediately after, and echo that to C:\test.txt

- see which exit code came from SAS.

 

I have to say, though, that I am always astonished by how complicated such simple tasks are in Windows. By $DEITY, am I glad my SAS server runs on UNIX!

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 12 replies
  • 687 views
  • 0 likes
  • 3 in conversation