Runtime.WriteProgramFile

Prototypes

static void WriteProgramFile( String sPathName, Matrix mText )

static void WriteProgramFile( String sPathName, String sText )

Parameters

String sPathName
The path and filename of the program file you want to create. The filename extension should be .sx (for a program file) or .sxs (for a module source file).

Matrix mText
A character vector in which each element contains one line of an IMLPlus program. The elements should not contain any line ending characters such as carriage returns or line feeds. IMLPlus adds the appropriate Windows line ending characters automatically.

String sText
A string containing the source code for an IMLPlus program. Each line of the program should be terminated with one of the following line ending sequences: \n, \r, \r\n. For example: "x = 1;\nprint x;\n"j. The j suffix on a literal string instructs IMLPlus to process control sequences such as \n, which inserts an ASCII line feed character. IMLPlus automatically translates the line endings from the convention used in sText to the Windows line ending convention used in the program file.

Remarks

This method creates a file that contains the source statements for an IMLPlus program. This method enables an IMLPlus program to write another IMLPlus program dynamically.

The Base SAS function TRANWRD is useful for performing string substitution when building the source statements for an IMLPlus program. See the example.

Example
run GetPersonalFilesDirectory( PathName );
PathName = PathName + "Programs\DynamicallyGeneratedProgram.sx";

arg1 = "The answer is";
arg2 = 42;

ProgramText = { "print '&arg1';",
                "print (&arg2);" };
ProgramText = tranwrd( ProgramText, "&arg1", arg1 );
ProgramText = tranwrd( ProgramText, "&arg2", strip(char(arg2)) );

print ProgramText;

Runtime.WriteProgramFile( PathName, ProgramText );
Runtime.RunProgramFile( PathName );
See Also

Runtime.RunProgramFile