2

I'd like to conditionally execute code depending on whether I'm in a Workspace or Stored Process server context.

I could do this by testing the existence of an automatic STP variable, eg _metaperson, but this wouldn't be very robust.

Assuming I already have a metadata connection, how best to check my server type?

Nickolay
  • 31,095
  • 13
  • 107
  • 185
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124

3 Answers3

2

Bulletproof way would be to create a macro variable that is initialised by the autoexec or config in the required server context.

Of course this would only work if you have access and permission to modify files stored in sas configuration folder.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Vasilij Nevlev
  • 1,449
  • 9
  • 22
  • 2
    it's not bulletproof though - somebody could subsequently create a similar macro variable in the other server context :-) – Allan Bowe Jan 26 '18 at 18:49
2

Hurrah - there is, in fact, an automatic variable that does just this - sysprocessmode (available since 9.4)

Extract from documentation:

SYSPROCESSMODE is a read-only automatic macro variable, which contains the name of the current SAS session run mode or server type, such as the following:

  • SAS DMS Session
  • SAS Batch Mode
  • SAS Line Mode
  • SAS/CONNECT Session
  • SAS Share Server
  • SAS IntrNet Server
  • SAS Workspace Server
  • SAS Pooled Workspace Server
  • SAS Stored Process Server
  • SAS OLAP Server
  • SAS Table Server
  • SAS Metadata Server

Being an automatic variable, it is of course read only: enter image description here

Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
1

The stored process server will preset the _PROGRAM macro variable with the program that is running. I do not know if this macro variable is read-only in the STP execution context.

But as you say, a program in the workspace context could set a _PROGRAM macro variable.

For workspace sessions look for _CLIENTAPP macro variable.

I am unaware of a function to call or immutable system option that can be examined. Try PROC OPTIONS in both contexts and see what pops out. An OBJECTSERVERPARMS value, if reported, is a list of name=value pairs. One of them would be server= and may differentiate.

Richard
  • 25,390
  • 3
  • 25
  • 38
  • Thanks for these ideas.. There was nothing in `options` :-/ But after some experimentation trying to do conditional tests on the `_webout` fileref (STREAM engine) I finally found `sysprocessmode` ! – Allan Bowe Jan 31 '18 at 09:06