Previous Page | Next Page

Functions and CALL Routines

LENGTHM Function



Returns the amount of memory (in bytes) that is allocated for a character string.
Category: Character
Restriction: I18N Level 2

Syntax
Arguments
Details
Comparisons
Examples
Example 1: Determining the Amount of Allocated Memory for a Character Expression
Example 2: Determining the Amount of Allocated Memory for a Variable from an External File
See Also

Syntax

LENGTHM(string)


Arguments

string

specifies a character constant, variable, or expression.


Details

The LENGTHM function returns an integer that represents the amount of memory in bytes that is allocated for string. If string is a numeric constant, variable, or expression (either initialized or uninitialized), SAS automatically converts the numeric value to a right-justified character string by using the BEST12. format. In this case, LENGTHM returns a value of 12 and writes a note in the SAS log stating that the numeric values have been converted to character values.


Comparisons

The LENGTHM function returns the amount of memory in bytes that is allocated for a character string, whereas the LENGTH, LENGTHC, and LENGTHN functions return the length of a character string. LENGTHM always returns a value that is greater than or equal to the values that are returned by LENGTH, LENGTHC, and LENGTHN.


Examples


Example 1: Determining the Amount of Allocated Memory for a Character Expression

This example determines the amount of memory (in bytes) that is allocated for a buffer that stores intermediate results in a character expression. Because SAS does not know how long the value of the expression CAT(x,y) will be, SAS allocates memory for values up to 32767 bytes long.

data _null_;
   x='x';
   y='y';
   lc=lengthc(cat(x,y));
   lm=lengthm(cat(x,y));
   put lc= lm=;
run;

SAS writes the following output to the log:

lc=2 lm=32767


Example 2: Determining the Amount of Allocated Memory for a Variable from an External File

This example determines the amount of memory (in bytes) that is allocated to a variable that is input into a SAS file from an external file.

data _null_;
   file 'test.txt';
   put 'trailing blanks   ';
run;

data test;
   infile 'test.txt';
   input;
   x=lengthm(_infile_);
   put x;
run;

The following line is written to the SAS log:

256


See Also

Functions:

LENGTH Function

LENGTHC Function

LENGTHN Function

Previous Page | Next Page | Top of Page