Previous Page | Next Page

Formats

$VARYINGw. Format



Writes character data of varying length.
Valid: in DATA step
Category: Character
Alignment: left

Syntax
Syntax Description
Details
Examples
Example 1: Obtaining a Variable Length Directly
Example 2: Obtaining a Variable Length Indirectly

Syntax

$VARYINGw. length-variable

Syntax Description

w

specifies the maximum width of the output field for any output line or output file record.

Default: 8 if the length of the variable is undefined. Otherwise, the default is the length of the variable
Range: 1-32767
length-variable

specifies a numeric variable that contains the length of the current value of the character variable. SAS obtains the value of the length-variable by reading it directly from a field that is described in an INPUT statement, reading the value of a variable in an existing SAS data set, or calculating its value.

Requirement: You must specify length-variable immediately after $VARYINGw. in a SAS statement.
Restriction: Length-variable cannot be an array reference.
Tip: If the value of length-variable is 0, negative, or missing, SAS writes nothing to the output field. If the value of length-variable is greater than 0 but less than w, SAS writes the number of characters that are specified by length-variable. If length-variable is greater than or equal to w, SAS writes w columns.

Details

Use $VARYINGw. when the length of a character value differs from record to record. After writing a data value with $VARYINGw., the pointer's position is the first column after the value.


Examples


Example 1: Obtaining a Variable Length Directly

An existing data set variable contains the length of a variable. The data values and the results follow the explanation of this SAS statement:

put @10 name $varying12. varlen;

NAME is a character variable of length 12 that contains values that vary from 1 to 12 characters in length. VARLEN is a numeric variable in the same data set that contains the actual length of NAME for the current observation.

Value of name* Results

----+----1----+----2----+
New York 8
         New York
Toronto 7
         Toronto
Buenos Aires 12
         Buenos Aires
Tokyo 5
         Tokyo
* The value of NAME appears before the value of VARLEN.


Example 2: Obtaining a Variable Length Indirectly

Use the LENGTH function to determine the length of a variable. The data values and the results follow the explanation of these SAS statements:

varlen=length(name);
put @10 name $varying12. varlen;

The assignment statement determines the length of the varying-length variable. The variable VARLEN contains this length and becomes the length-variable argument to the $VARYING12. format.

Values* Results

----+----1----+----2----+
New York
         New York
Toronto
         Toronto
Buenos Aires
         Buenos Aires
Tokyo
         Tokyo
* The value of NAME appears before the value of VARLEN.

Previous Page | Next Page | Top of Page