Functions and CALL Routines |
Returns the amount of memory (in bytes) that is allocated for
a character string.
-
string
-
specifies a character constant, variable,
or expression.
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.
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.
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
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
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.