# Writing to text files

Commands

OpenOutput [“filename”] ,<CLEAR>, <”delimiter”>

WText <"text"> <;&>

WDate <;&>

WTitle

WCell [row], [col], <subcol> <;&>

WRow [row], <col>, <subcol> <;&>

WCol [row], <col>, <subcol><;&>

WSheet <row, col, subcol><;&>

WBlock [row(s)]  [column(s)] <row label> <;>

WTCol [row, col] <, subcolumn><;&>

WTRow [row] <,col, subcol> <;&>

WTSheet <row, col, subcol><;&>

WTBlock [row(s)]  [columns to include] <row label> <;>

WVersion

CloseOutput

Explanation

Prism offers two methods for writing results from a script. The previous section explains how to write tables. A more general method, writing to a text file, is explained here. Generally, you’ll find it easier to write to tables (previous section) but may find uses for  the extra flexibility of writing to text files.

The first step is to use the OpenOutput command to open (or create) a file to contain the text the script will output. If you don't precede the file with disk and directory, Prism will use the path defined in SetPath. If there is no SetPath command, then Prism assumes that you want to use the directory that contains the script. If you include a delimiter, say “,” it will appear between entries. Otherwise the output file will be delimited with tabs.

If the output file already exists, Prism appends to that file unless you have included CLEAR.

Results will be tab delimited unless you include an alternative delimiter in the OpenOutput statement.

Examples:

OpenOutput C:\gp25\output.txt, Clear

OpenOutput C:\data\july97, “,”

You can write (export) data and results to the text file using any of the commands that begin with W (or by creating a text or CSV table as described in the next section).

If you end any of the W commands with a semicolon, the next W command will add text to the same line, following a tab. If you end with an ampersand (&), the next W command will add text to the same line, without a tab. If you omit the semicolon or ampersand, Prism inserts the codes for carriage return and line feed so the next W command will write to the next line in the file.

The most useful W command is WCell which writes out the contents of one cell in a data or results table. You need to specify the row and column of the cell to write. Row 0 refers to the row of column titles, and row 1 is the first row of data. Column 0 refers to the X column, and column 1 is the first Y column (column A).

You can also write out entire rows or columns, or the entire sheet, at once. The commands that begin with WT transpose the data (so each row becomes a column) before writing to the text file.

WVersion writes the version of Prism you are using, to fully document your results.

Note that the WTable command is distinct from the set of commands described here, despite the fact that it begins with the letter W.

Variables

Use the following variables when writing text:

%D   Date and time this file was last saved, e.g. "Tuesday, September 16, 2014 4:08:10 PM"

%P   File name of the Prism project

%S   Sheet name

%V   Prism version