Greg Rogers
Greg Rogers

Reputation: 1031

Invoking SAS 9.2 to edit a program from the command line (windows)

I've been Googling for an hour and can't find what should be the easiest thing.

I want to invoke SAS from the command line to edit a SAS program.

If I do this:

C:\Program Files\SAS\SASFoundation\9.2(32-bit)\sas.exe mysasprogram.sas

it simply executes mysasprogram.sas.

Help!

Thanks!

Upvotes: 3

Views: 1720

Answers (4)

Richard
Richard

Reputation: 27536

Take a read of "Double-Clicking a SAS® File: What Happens Next?" Sandy Gibbs, Michele Mosca, and Donna Bennett, SAS Institute Inc.

The raw gist (for File Explorer in Windows operating system) is that the command

"C:\PROGRA~1\SASHome\SASFOU~1\9.3\core\sasexe\SASOACT.EXE"
   action=Open datatype=SASFile filename="%1" progid=SAS.Application.903 

needs to be associated with the .sas filetype.

Upvotes: 1

David C
David C

Reputation: 7534

I had some trouble getting vasja's answer to work -- the call to %sysget was unable to retrieve the variable.

I ended up using a single file (launchsas.cmd):

set fn=%1
set fn=%filename:"=%
set command="%%let filename='%fn%'; dm 'whost;include &filename.;';"
start "start" C:\path\to\sas.exe -initstmt %command%

Note that the creation of the "filename" variable is to avoid problems with embedded quotation marks.

Upvotes: 0

Greg Rogers
Greg Rogers

Reputation: 1031

After digging through my registry and some more Googling, I got to this solution, that seems to work. However, I haven't played enough to know the differences between SAS.EXE and SASOACT.EXE.

SASOACT.EXE action=Open datatype=SASFile filename="mysasprogram.sas"

Upvotes: 1

vasja
vasja

Reputation: 4792

Create files:

E:\sasedit.bat

set _pgm=%1
start "start" "C:\Program Files\SASHome\SASFoundation\9.3\sas.exe" -autoexec "E:\autoexec.sas"

E:\autoexec.sas

%let _pgm=%sysget(_pgm);
dm "whost;include '&_pgm';";
  • mysasprogram.sas with anycontent in a path that doesn't require quotes (in DOS).

Run command:

E:\sasedit.bat E:\pathtomyfile\mysasprogram.sas

The syntax of autoexec code: DM is display manager, WHOST command is calling SAS Enhanced Editor.

To use this with path requiring quotes you'd have to provide path in quotes and add some quoting treatment to autoexec code.

Another way to run some initial commands is via INITSTMT SAS command line option, but there will we have a problem with lots of quoting.

Upvotes: 4

Related Questions