RATS 11
RATS 11

Data Types /

STRINGS and LABELS

Home Page

← Previous Next →

STRING and LABEL variables can be used for graph headers, for labeling output, or for picture codes. A LABEL is limited to 16 characters (the length of a RATS variable name), while a STRING can be up to 256.

 

You can create these variables with COMPUTE, and you can create a "formatted" STRING using DISPLAY with the STORE option. 

 

You can also read strings or labels from an external file using the instruction READ or from the input file with INPUT.

 

Operators

The + operator, when applied to two strings, concatenates them. If there is a space at the end of the first string or the beginning of the second, it will be retained in the combined string. If not, no blanks will be inserted and the two strings will run together. If you need spacing, you may need to add it, for instance, with s1+" "+s2. If there is more than one blank between the two, the extras will be removed, leaving just one blank as spacing.

 

You can also use the + operator to add (the character representation of) an integer to the end of a string. For instance "ABC"+I will produce the string ABC13 if I=13.

& Prefix

Anywhere that RATS expects an undelimited string (such as for the file name on an OPEN instruction or a picture code on DISPLAY), you can use a LABEL or STRING variable prefixed with the & symbol. For instance,

 

OPEN DATA &FNAME

 

will open the file whose name is stored in FNAME.

 

String/Label Functions

Below are most of the functions available for working with strings and labels.

 

%concat(first,last)

Concatenate two labels

%datelabel(t)

Date label for a given date/entry number

%l(series)

Get label of a series

%label(variable)

Get label of a series or other variable

%left(s,n)

Left substring

%mid(s,m,n)

Middle substring

%right(s,n)

Right substring

%s(label)

Get (or create) series with a given label

%strcmp(s1,s2)

Compare two strings (case-sensitive comparison)

%strcmpnc(s1,s2)

Compare two strings disregarding case

%strescape(s,chars,escape)

Returns copy of string with special characters "escaped"

%strfind(s,f)

Searchs s for string f, returning position if found, 0 if not

%string(n)

Convert integer value to a string

%strlen(s)

Returns the length of a string

%strlower(s)

Convert string to lower case

%strrep(s,n)

Repeats a string

%strtrim(s)

Returns a copy of a string with leading and trailing spaces and quotes removed

%strupper(s)

Convert string to upper case

%strval(x,f)

String showing a numerical value

%value(s)

Get numeric value from a string

 

Examples

This creates in HEADER a string such as Transformations of FYGM3

 

compute header="Transformations of "+%l(series)

 

 

 

This creates in DLABEL a string describing the range from START to END using date strings:

 

compute dlabel="Using data from "+%datelabel(start)+" to "+%datelabel(end)

 

 

 

This creates in KEYLABEL a string such as GDP \\\\7.391. (The \\\\ is used in several situations, such as graph labels, to show a line break).

 

disp(store=keylabel) %l(series)+" \\\\" *.### value

 

 

 

This creates an Excel spreadsheet whose name is formed by adding “.XLS” to the name of series I, and which has the data for series I. Note that if you don’t put the & in front of FNAME, the file name is literally “fname”, not the string that FNAME holds.

 

declare string fname

compute fname=%l(i)+".XLS"

open copy &fname

copy(format=xls,org=col,dates) / i

 


Copyright © 2025 Thomas A. Doan