1

I am using SAS 9.4 for Windows 7. When I run anything in batch mode, such as SASUnit, I get a dialog stating

This window is unavailable in line-mode.

My AUTOEXEC.sas contains these two lines which open the work library and maximize the IDE window:

dm 'dmsexp; expand libraries; expand work;';
dm 'awsmaximize on';

The error happens because there is no windowing environment when run in batch. The dm statements don't apply.

It seems like the obvious solution, i.e. test whether SAS is running in batch mode or not, doesn't apply on Windows. The SYSENV variable "reports whether SAS is running interactively." Yet on Windows, SYSENV always contains the value FORE, the value which indicates "when you run SAS interactively through a windowing environment".

Is there a workaround for this other than opening my AUTOEXE.sas and commenting out those two lines every time I need to run something in batch? Maybe there is command-line switch, such as --no-init-file for Emacs, which skips running AUTOEXEC.sas?

1
  • There is -noautoexec command line option if you want to use that. Commented Jul 5, 2018 at 15:41

3 Answers 3

4

If you want to know whether or not you can use Display Manager commands just check if Display Manager is running or not.

%if DMS=%sysfunc(getoption(dms)) %then %do;
  dm 'dmsexp; expand libraries; expand work;';
  dm 'awsmaximize on';
%end;

Note starting with SAS 9.4M5 you could include this exact code in your autoexec.sas file without having to first wrap it into a macro.

If you are using an old version of SAS then you could use a data step with call execute() instead.

data _null_;
  if 'DMS'=getoption('dms') then call execute(
  "dm 'dmsexp; expand libraries; expand work';dm 'awsmaximize on';"
  );
run;
Sign up to request clarification or add additional context in comments.

3 Comments

I tracked this down as the source of a bizarre bug. If AUTOEXE.sas contains only the lines given in your response, then the Enhanced Editor opens to the WORK library and maximizes. Awesome. Yet, the following error occurs. When using a new SAS session (which runs AUTOEXE.sas on opening), submitting **; throws an ERROR 180-322: Statement is not valid or it is used out of proper order. The error only happens once. Submitting **; again causes no error. I was able to fix this by wrapping your response in a macro and calling it: %macro SetIDEDefaults(); ... %mend; %SetIDEDefaults();.
Rereading your post, I see that you say that it should be wrapped in a macro! Thanks!
Starting with release SAS 9.4M5 you do not need to create a macro to run this type of simple %IF/%THEN/%DO/%END block of code. If your version of SAS is older then yes you need to wrap that code in a macro and call the macro. Or use data step with call execute to conditionally run the code.
3

Just use the -noterminal option when invoking SAS as a batch job.

https://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#p16esisc4nrd5sn1ps5l6u8f79k6.htm

Also :

Note: The -NOSTATUSWIN option enables you to run SAS in batch mode so that no windows are displayed. You can add options such as -NOTERMINAL, -NOSPLASH, -NOSTATUSWIN, and -NOICON to prevent the windows from being displayed.

Comments

0

The dm statement is doing it (inside the code). It got solved when I commented that dm statement.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.