As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Determining the filepath root in Enterprise Guide

From sasCommunity
Jump to: navigation, search

Problem Overview

One of the more difficult things to handle in the SAS 9 Business Intelligence architecture is how to handle the promotion of code, data, etc. from one environment to another (for example, from Development to Test to Production.

This article documents a trick/technique that can make it easier to migrate Enterprise Guide (EG) projects from one environment to another. The issue is that there are often occasions where it is necessary to code file paths in an EG project (just like in any other SAS program) and those file paths will typically need to be updated when the code is moved.

Solution Overview

By obtaining the default file path in EG, it would be possible to specify any file references to be relative to that location, thus minimizing any changes needed when migrating code. Thanks to Bubba Talley of SAS Technical Support (who provided the code sample below), it is possible to do just that.

The basics of the techniques follows. Consider a dev/test/prod environment where the file paths might be:

  • /projects/dev
  • /projects/test
  • /projects/prod

Or perhaps something like:

  • /serverA/projects/dev
  • /serverB/projects/test
  • /prodServer/projects

And under these directories you might have directories like dwdata, staging, storedprocesses, and so on.

Defining the EG Default File Path

So you will want EG in each environment to point to the appropriate directory. Assuming there is a separate Metadata Server for each environment you can accomplish this by going into SMC for each environment and:

  • Expand Server Manager
  • Expand SASMain
  • Expand SASMain - Workspace Server
  • Right click on SASMain - Workspace Server (at the bottom of the tree)
  • Select Options
  • Select Advanced Options
  • Select File Navigation Tab
  • Select Path and fill in the right value for the current environment (e.g., Dev or Test or Prod or whatever)

You have now specified a separate default directory path for each environment.

SAS Code

Next, include the following code in your project (it could also perhaps be added to the autoexec for the Workspace Server - that is something yet to be tested) to get the value of the default file path and create a macro variable:

%let root = ; 
data _null_; 
length obj id navpath $256 type $32; 
call missing(id,type,navpath); 
obj="omsobj:Property?Property[@PropertyName='FileNavigation']
     [AssociatedObject/ServerComponent[@Name ? 'Workspace']UsedbyComponents/LogicalServer/UsedByComponents/ServerContext[@Name=&_SASSERVERNAME.]]"; 
rc=metadata_resolve(obj,type,id); 
put rc= type=  id=;
if (rc > 0) then 
do; 
   rc2=metadata_getattr(obj,"DefaultValue",NavPath); 
   call symput('Root',trim(NavPath)); 
end; 
else put 'ERROR: No Property found ' obj=; 
run; 
 
%put NOTE: Environment Root is: &root..;

And your programs can now define libnames/filenames using statements like:

 libname dwdata "&root/dwdata";

When the projects are moved, there is no need to edit anything to change file paths.

Code Comments

Note the user of the macro variable _SASSERVERNAME in the above code. This addresses the fact that there may be more than one Application Server with a Workspace defined to the repository, for example you might have:

  • SASApp - Workspace Server
  • SASMain - Workspace Server.

So the code uses the _SASSERVERNAME macro variable which contains the name of the Application Server (ServerContext) such as SASMain. Unfortunately there is no corresponding macro variable that can be used if the name of the Workspace Server is changed to something other than Workspace. However, when implementing an application for customer, this is something that can probably be dealt with.

Other Applications

Such techniques can also be used to get info regarding other servers (e.g., the Stored Process Server).

Future Enhancements

It would be even easier if the code could be included in the autoexec file used to start Enterprise Guide. Unfortunately the information needed to run this code is not available when the autoexec runs. However a request to specify that a code node be executed when opening an EG Project has been submitted to SAS and could be used for this purpose once/if implemented.