TEMPLATE Procedure: Creating Markup Language Tagsets

SET Statement

Creates or updates a user-defined variable and its value.

Syntax

Required Arguments

dictionary-variable
specifies an array that contains a list of numbers or text strings that is identified by a key. dictionary-variable has the following form:
$dictionary-variable['key']
['key']
specifies a subscript that contains text or a variable that has a character value.
Requirement:Enclose key in quotation marks and brackets.
Tip:key is case preserving and case sensitive.
Example:The following example puts two key value pairs into the dictionary variable MyDictionary:
set $mydictionary['URL1'] 'links internally';
 set $mydictionary['URL2'] 'links externally';
Requirement:dictionary-variable must be preceded by the '$' symbol.
Tips:Dictionary variables are accessed sequentially by using the ITERATE and NEXT statements. See ITERATE Statement. Also see NEXT Statement.

After they are created, dictionary variables are globally available in all events until you delete them by using the UNSET Statement.

entry
specifies the value of a dictionary variable, list variable, scalar variable, or stream-variable. An entry is one of the following:
function
specifies a DATA step function.
Restriction:Functions cannot be nested.
See:SAS Functions and CALL Routines: Reference for information about SAS functions
text
specifies a string of text.
Requirement:text must be enclosed in quotation marks.
variable
specifies any event variable, style variable, dynamic variable, user-defined variable, or DATA step function whose value you want to output.
Restriction:variable cannot be a stream variable.
Requirement:User-defined variables must be preceded by a '$' character.
Tips:If you assign a variable entry that is the name of a memory variable to stream variable, then the stream variable resolves as the value of the memory variable. For example, the following program uses the memory variable $MyStream as a stream variable:
set $mystream 'test';
 open $mystream;
 put 'The memory variable $mystream is being used as a stream variable';
 close;
Therefore, the following statements are equivalent:
put $$test;
 putstream $mystream;
 putstream test;
The following statements are also equivalent:
unset $$test;
 delstream $mystream;
 delstream test;

User-defined variables are not case sensitive.

For information about variables, see Understanding Variables.

Event Variables for a list of event variables

list-variable
specifies an array that contains a list of numbers or strings of text that are indexed. list-variable has the following form:
$list-variable[<index>]
[<index>]
specifies a subscript that contains a number or numeric variable. The index identifies the location in the list to add an entry. If you omit the index and only specify empty brackets, or if the value of the index is greater than the highest index number, then the SET statement appends the entry to the end of the list.
Requirements:Specify brackets [ ], even if you omit an index.

Enclose index in brackets.

Tip:List entries are accessed by positive or negative indexes. Positive indexes start at the beginning of a list. Negative indexes start at the end of a list. For example, the following list variable, $Mylist[2], identifies the second entry in the list variable $Mylist. In this case, the index is 2. The list variable $Mylist[-2] identifies the second entry from the end of the list variable $Mylist. In this case, the index is [-2].
Example:The following example adds three values onto the end of the list variable MyList and modifies the value of the second entry.
set $mylist[] 'one';
 set $mylist[] 'two';
 set $mylist[] 'hello';
 set $mylist[2] 'This is Really two';  
Requirement:list-variable must be preceded by a '$' symbol.
Tips:List variables are accessed sequentially by using the ITERATE and NEXT statements. See ITERATE Statement and NEXT Statement.

After they are created, list variables are globally available in all events until you delete them using the UNSET Statement.

scalar-variable
an area of memory that contains numeric or character data.
Requirement:Scalar variables must be preceded by the '$' symbol.
Tip:After they are created, list variables are globally available in all events until you delete them using the UNSET Statement.
stream-variable
specifies a stream variable, which is a temporary item store that contains output.
While the stream variable is open, all output from PUT statements is directed to the stream variable until it is closed.
Requirement:user-defined-variable-name must be preceded by the '$$' symbol.
Tip:If you assign a variable entry that is the name of a memory variable to stream-variable, then the stream variable resolves as the value of the memory variable. For example, the following program uses the memory variable $MyStream as a stream variable:
set $mystream 'test';
 open $mystream;
 put 'The memory variable $mystream is being used as a stream variable';
 close;
Therefore, these statements are equivalent:
put $$test;
 putstream $mystream;
 putstream test;
These statements are also equivalent:
unset $$test;
 delstream $mystream;
 delstream test;

memory variables

Optional Argument

event-statement-condition(s)
specifies one or more conditions that must be true for the event statement to execute.
Requirement:event-statement-condition(s) must be preceded by a slash (/).
See: For information about these conditions, see Event Statement Conditions.

Adding Entries to Dictionary Variables

Use this form of the SET statement to add an entry to a dictionary variable.
SET $dictionary-variable entry </ event-statement-condition(s)>;
A dictionary variable is an array that contains a list of numbers or text strings that is identified by a key. A dictionary variable has, as part of its name, a preceding '$' symbol and a subscript that contains a text string or a variable that has a character value. The text or variable within the subscript is called a key. Keys are case preserving and case sensitive. After they are created, dictionary variables are globally available in all events and persist until you unset them with the UNSET statement.
An entry is a variable, string of text, or function. If a string of text follows the dictionary variable, then the entry becomes a key-value pair. For example, the following program adds two key-value pairs to a dictionary:
set $mydictionary['URL1'] 'links internally';
set $mydictionary['URL2'] 'links externally';

Adding Entries to List Variables

Use this form of the SET statement to add an entry to a list variable.
SET $list-variable entry </ event-statement-condition(s)>;
A list variable is an array that contains a list of numbers or text strings that are indexed. As part of their name, list variables have a preceding '$' symbol and a subscript that is empty or contains a number or numeric variable. The number within the subscript is called an index. After they are created, list variables are globally available in all events and persist until you unset them with the UNSET statement. List entries are accessed by positive or negative indexes. Positive indexes start at the beginning of a list. Negative indexes start at the end of a list.
For example, the following list variable, $Mylist[2], identifies the second entry in the list variable $Mylist. In this case, the index is 2. The list variable $Mylist[-2] identifies the second entry from the end of the list variable $Mylist. In this case, the index is [-2].