SASCodeRunner7 Documentation

Introduction

The SASCodeRunner7 ActiveX component (DLL) gives you the ability to run SAS code from within another Windows programming environment, such as Visual Basic and Active Server Pages. SASCodeRunner runs the SAS code that you submit to it in the background and returns the resulting Log, Lst, and PutFiles (alternative text output destinations) to your application for additional processing.

The SASCodeRunner7 object model consists of a single createable object called CodeRunner. So instantiating SASCodeRunner7 in VB code is as simple as: Dim S as SASCodeRunner7.CodeRunner.

Properties

CleanOutput
DebugInfo
Log
Lst
PutFile
SafeFormChar
SASCode

Methods

Execute
Reset

CleanOutput Property

A read/write Boolean property (default: True) that when set to True replaces all characters in the 1-31 code range with '%CharCode' except for CR and LF (10 and 13). So, for example, a character code of 15 is replaced with %15. This property exists for alleviating the problems that occur when clients do not correctly handle the special characters that appear in some forms of SAS output. Setting this property to False turns off character code converting which preserves the special characters as is.

DebugInfo Property

A read-only String property that provides a wealth of information about what's going on (SASCode, Log, Lst, PutFiles, etc) with the SASCodeRunner object.

Execute Method

A function that executes the SAS code assigned to the SASCode property. After execution is finished, a String is returned indicating how it went. The string "OK" is returned if the SAS code was executed successfully, otherwise an error message is returned. It is important to understand that this function does NOT look to see if your SAS code experienced errors, only if SAS executed. Parse the Log property value to check for SAS programming errors.

This method has two optional parameters: SASRoot, and SASConfig.

The parameters enable you to provide the fully-specified locations for the SAS Root (where SAS.EXE is located on your machine) and the SAS configuration file (where SASV8.CFG or similar is located on your machine). If the SASRoot is omitted, SASCodeRunner will try to find SAS.EXE in :\Program Files\SAS Institute\SAS\V8\, where is some drive letter from C to Z. If SAS is installed elsewhere, you'll have to supply the SASRoot parameter. Likewise, with the second parameter, SASCodeRunner will try to find SASV8.CFG in the SASRoot directory, but if it's not there, or you want to use a different config file, you'll have to supply the SASConfig parameter.


Log Property

A read-only String containing the SAS log text from the most recent execution of SAS code. Can be used to check for and show errors. For example, one simple way of handling errors is to check for the string "ERROR" in the Log property and dump the Log to the browser if there is an error.
If Instr(1, S.Log, "ERROR")>0 Then
    'An error occurred in SAS.
    Response.Write "<div style='color: red; font-weight: bold'>"
    Response.Write "An error occurred in the SAS program: " 
    Response.Write "<PRE>" & S.Log & "</PRE>"
    Response.Write "</div>"
Else
    'Do stuff when SAS code does not have errors, so as...
    Response.Write S.PutFile(1)
End If
Of course, this may not be sophisticated enough or appropriate for some apps.

Lst Property

A read-only String containing the SAS lst (normal output) text from the most recent execution of SAS code.

PutFile Property

A read-only String property that provides access to the "special" text output files that were created during the most recent execution of SAS code. To output to a PutFile, use a fileref alias of the form _PUTn, where n is an integer from 1 to 9999, without leading zeros. Including _PUTn in your SAS code causes a fileref with alias _PUTn to be automatically allocated and managed for you (i.e., it's deleted when the SASCodeRunner7 object is destroyed).

Calling this property providing the putfile number as the first parameter returns the contents of the putfile. A second optional Boolean parameter (default: False) returns the phsyical path of the putfile (if True).

For example, if you provide the SASCode property with either of these SAS code blocks and call the Execute method, a single PutFile is created.

data _NULL_; *This outputs the current date to the putfile;
   file _PUT8;
   put "&sysdate";
run;
ods html file=_PUT8; *This directs the proc whatever HTML output to the putfile;
proc whatever;  run; *Your actual proc would go here;
ods html close;

Back in the client application (e.g., an ASP file), to retrieve the value (e.g., 11JUL02), call the PutFile method like this: PutFile(8). To get the physical path (e.g., C:\WINNT\TEMP\tmpPutFile_PUT1_711200283400_06120874.put), call the PutFile method like this: PutFile(8, True). This latter technique is not routinely used, but if you do use it you will notice that the filenames are long and random. This is necessary for SASCodeRunner to work correctly in a multiuser environment such as the web.


Reset Method

A parameterless subroutine that resets all properties to their default values.

SafeFormChar Property

A read/write Boolean property (default is True) that includes the SAS code options formchar='|-++++++++++=|-/|<>*'; at the beginning of the program when True. The intent of this property is to make the output render more consistently in web browsers. If the value is False, the options formchar statement is not used.

SASCode Property

A read/write String property for managing the SAS code text that will be run when the Execute method is called. When reading this property, all the SAS code is returned as a single string. The assignment behavior is more complex and is explained as follows:
  • When called multiple times, the existing SASCode value is appended to, not overwritten. To clear the value, use the Reset method.
  • Plain text can be appended as a single string, or text from an external text file.
  • To append the text contained in an external text file (e.g., a .sas program file) assign the full path and filename of the text file. An error will occur if the text file does not exist. So, for example, if we have a SASCodeRunner7.CodeRunner object named S then the VB statement S.SASCode = "c:\temp\myprogram.sas" will append the text stored in the .sas file to the SASCode property value.

SASCodeRunner7 was produced in 2002 by David Rubanowice, Group Health Cooperative, Seattle, WA

Hosted by www.Geocities.ws

1