09-14-2011 01:26 AM
I want to run a sas program in batch mode and have the .log and .lst file saved in the same directory as the .sas file.
However, the file associations seem to have been messed up on our Windows 2008 server (SAS 9.2 64bit). There is no 'Submit in batch mode' option and if I right click on the program test.sas and choose "Open with SAS 9.2 for Windows" I get the error message:
Error: Insufficient authorization to access C:\Window\system32\test.log
Similarly, if I create a batch file with command "c:\program files\SAS\SASFoundation\9.2\sas.exe" %1
and choose this, I get the same error message.
I don't have admin access to this server, but it seems to me that this should be possible by using an appropriate batch file. Any suggestions? (Incidentally, SAS works fine in interactive mode if I start it from the program menu).
09-14-2011 09:34 AM
You will probably need to work with your server administrator on this. He has modified the working environment from the default delivered by SAS.
The error associated with "Open with SAS 9.2 for Windows" is because it is trying to open interactive SAS and direct the log to the system32 subdirectory. In a lot of offices, the system32 subdirectory is read-only by Windows policy. If so, the note that Art cites will not help.
A workaround that you might be able to do is to modify the right-click behavior on .sas files to mimic the conditions that are used in the SAS icon. In windows explorer, go to tools --> folder options and go to the SAS file type. You can create a new right-click option and the paste and modify the string from the interactive icon. (This depends on how tightly controled your desktop is.)
09-14-2011 04:23 PM
you can add the -log option to define a different location for the log output that is in a properly writable directory. Also if executing in batch mode you should also use the -batch option.
c:\program files\SAS\SASFoundation\9.2\sas.exe -batch -log c:\mylog.log -sysin c:\mypgm.sas -print c:\mylst.lst -sysparm My Passed Paramameter
09-14-2011 07:15 PM
I knew about the solution proposed by FriedEgg, however it doesn't fully solve the problem. I want the log file to automatically have the same name as the submitted program (apart from the extension).
(The approach suggested by Doc@Duke doesn't work in Windows 7 or Server 2008 - the ability to configure file type associations has been removed from the user interface)
I presume there must be a way to create the log file name and location within a batch file using some scripting language, but surely there must be a way of asking SAS to do this (since that is what it normally does).
09-14-2011 07:32 PM
Actually, I've discovered the scripting is not that hard. A batch file with the following single line seems to do the trick
"c:\program files\SAS\SASFoundation\9.2\sas.exe" %1 -nologo -batch -log "%~dpn1.log" -print "%~dpn1.lst"
09-14-2011 08:11 PM
Basically this is the direction I was meaning for you to take my post. Here is another example:
if NOT (%1)==() GOTO RUN
ECHO ----Batch Program Notes----
ECHO Required Parameters:
for /F "tokens=2,3,4 delims=/ " %%i in ('date/t') do set d=%%k%%i%%j
for /F "tokens=1,2,3 delims=:. " %%i in ('time/t') do set t=%%k%%i%%j
"C:\Program Files\SAS\SASFoundation\9.2\sas.exe" -batch -nologo -sysin "%1" -sysparm "%*" -log "%~dpn1_%d%_%t%.log" -print "%~dpn1_%d%_%t%.lst"
Wow, it has been a long time since I have thought about windows bats. I prefer *nix.
09-16-2011 03:36 AM
I've now come across another problem. I start my SAS program with a batch file with
"c:\program files\SAS\SASFoundation\9.2\sas.exe" %1 -nologo -batch -ls 130 -config D:\SAS\SASV9.cFG -log "%~dpn1.log" -print "%~dpn1.lst"
The log file now has the error
NOTE: Writing Body file: sashtml.htm
ERROR: Insufficient authorization to access C:\Windows\system32\sashtml.htm.
WARNING: No body file. output will not be created.
When I start SAS interactively, it has the results being directed to the Work folder (which is located elsewhere). How do I control this in the batch job?
09-16-2011 04:09 AM
Setting the option SASINITIALFOLDER fixed this. Would be nice if there was a document which brought together all the options on how to start SAS in the windows environment.
09-15-2011 01:51 PM
On "(The approach suggested by Doc@Duke doesn't work in Windows 7 or Server 2008 - the ability to configure file type associations has been removed from the user interface)", that is still there in Win 7 (I don't use Winserver to check). It appears that your windows network administration got a bit overzealous with the policy editor.
10-07-2011 11:28 AM
I use a bat file to set pgm, log and output like this-
set sas=C:\Program Files\SAS\SAS 9.1\sas.exe
"%sas%" "%src%testpgm.sas" -nosplash -print "%prt%" -log "%log%"
That way they'll all be named the same as the program
10-08-2011 10:27 AM
The real problem is the directory that Windows is using as the current working directory when it starts SAS.
If you open a Command Window and move to the directory with your program in it and type the command:
> "c:\Program Files\SAS\SAS 9.2\sas" myprogram
It will run SAS 9.2 in batch using myprogram.sas as input and writing the log to myprogram.log and output to myprogram.lst.