Your SAS programs, embedded in web apps and elsewhere

Detect if code is running in stored process

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 127
Accepted Solution

Detect if code is running in stored process

Hi,

I have code that is sometimes executed normally (windows sas 9.2, EG 4.3) and sometimes executed via a stored process

(the two are linked together in Eguide)

I would like to execute code only if It's running from a stored process.

%If (this is running in a stored process)

     %then %do;

     %stpbegin;

     %end;

I thought to do it with a system variable but I couldn't find any that gives such information.

thanks,


Accepted Solutions
Solution
‎08-21-2012 04:25 AM
Super User
Super User
Posts: 7,050

Re: Detect if code is running in stored process

I do not have access to run stored process, but when I played with EG a few years ago I found that I could tell if I was running code from EG because it created macro variable _CLIENTAPP.  It also created macros (not variables) name ENTERPRISEGUIDE and _EG_CONDITIONAL_DROPDS.  I am not sure if that is still true or if it would distinguish between code submitted via EG vs stored process execution.

View solution in original post


All Replies
PROC Star
Posts: 1,322

Re: Detect if code is running in stored process

Hi,

I don't understand what you mean by executed normally vs executed via a stored process.  Can you explain a bit more?

Is the code executed by Enterprise Guide in each scenario?

Are you saying you have a stored procedure, and the source code of the stored procedure %includes some other code?  And you want to tell if that second bit of code has been %included by a stored process or not?

Thanks,

--Q.

Frequent Contributor
Posts: 127

Re: Detect if code is running in stored process

Hi,

A: Executed normally = a program executed by Eguide

B: executed as Stored Process = Stored Process executed by EGuide OR executed by web (Stored Process Web Application)

Lets say I have this little bit of code:

%If &MyCondition

     %then %do;

          %stpbegin;

     %end;


I need to find the right condition to make this code do nothing when A and do "%stpbegin" when B.

Let me know if I'm not yet clear enough,

Thanks,

Solution
‎08-21-2012 04:25 AM
Super User
Super User
Posts: 7,050

Re: Detect if code is running in stored process

I do not have access to run stored process, but when I played with EG a few years ago I found that I could tell if I was running code from EG because it created macro variable _CLIENTAPP.  It also created macros (not variables) name ENTERPRISEGUIDE and _EG_CONDITIONAL_DROPDS.  I am not sure if that is still true or if it would distinguish between code submitted via EG vs stored process execution.

Frequent Contributor
Posts: 127

Re: Detect if code is running in stored process

That's exactly what I was looking for Smiley Happy

%put &_CLIENTAPP;

A:

'SAS Enterprise Guide'

B:

SAS Enterprise Guide; CLR 2.0.50727.3620; Microsoft Windows NT 5.1.2600 Service Pack 3

OR

StoredProcessService 9.2; JVM 1.6.0_16; Windows Server 2008 (amd64) 6.1

Thanks !

Frequent Contributor
Posts: 127

Re: Detect if code is running in stored process

Final thing :

%macro conditionalstpbegin() / store

DES='Conditionally executes %stpbegin';

  %put &_CLIENTAPP;

  %if &_CLIENTAPP = 'SAS Enterprise Guide' %then %do;

  %put Not Stored Process °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°;

  %end;

  %else %do;

  /* SAS Enterprise Guide; CLR 2.0.50727.3620; Microsoft Windows NT 5.1.2600 Service Pack 3

  OR

  StoredProcessService 9.2; JVM 1.6.0_16; Windows Server 2008 (amd64) 6.1 */

  %put Stored Process °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°;

  %STPBEGIN

  %end;

%mend conditionalstpbegin;

%conditionalstpbegin;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 437 views
  • 6 likes
  • 3 in conversation