BookmarkSubscribeRSS Feed
BruceBrad
Lapis Lazuli | Level 10

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).

16 REPLIES 16
art297
Opal | Level 21

The following might be of help: http://support.sas.com/kb/10/856.html

Doc_Duke
Rhodochrosite | Level 12

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.)

Doc Muhlbaier

Duke

FriedEgg
SAS Employee

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

BruceBrad
Lapis Lazuli | Level 10

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).

BruceBrad
Lapis Lazuli | Level 10

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"

FriedEgg
SAS Employee

Basically this is the direction I was meaning for you to take my post.  Here is another example:

$cat example.bat

@echo off

if NOT (%1)==() GOTO RUN

ECHO ----Batch Program Notes----

ECHO Required Parameters:

ECHO   [program_fullpath]

ECHO ---------------------------------------

GOTO END

:RUN

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"

:END

Wow, it has been a long time since I have thought about windows bats.  I prefer *nix.

BruceBrad
Lapis Lazuli | Level 10

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?

BruceBrad
Lapis Lazuli | Level 10

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.

Arsenio_Staer
Calcite | Level 5

BruceBrad,

I got the same error, when trying

     ods html image_dpi=600;

Any idea how you corrected this sashtml.htm error?

Thanks!

Doc_Duke
Rhodochrosite | Level 12

Bruce,

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.

Doc

BruceBrad
Lapis Lazuli | Level 10

Doc, do you mean under control panel/programs/default programs? You can do some things there, but not (it seems) control parameters associated with programs.

Doc_Duke
Rhodochrosite | Level 12

No, under tools --> folder options .  That's where you can add/modify the file associateions in windows.

ChrisSelley
Calcite | Level 5

Hi Bruce

I use a bat file to set pgm, log and output like this-

set sas=C:\Program Files\SAS\SAS 9.1\sas.exe

set src=C:\SAS\Source\

set log=C:\SAS\Log\

set prt=C:\SAS\Output\

"%sas%" "%src%testpgm.sas" -nosplash -print "%prt%" -log "%log%"

exit

That way they'll all be named the same as the program

Chris

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 16 replies
  • 15448 views
  • 5 likes
  • 9 in conversation