Published on :
Data Manipulation CREATION_INTERNE

Demonstration of String Length Functions

This code is also available in: Deutsch Español Français
Awaiting validation
This script illustrates the differences between the functions `length` (length without trailing blanks), `lengthn` (similar to length but returns 0 for missing values), `lengthc` (variable storage length) and `lengthm` (allocated memory).
Data Analysis

Type : CREATION_INTERNE


Data is generated directly in the code via a DATALINES statement.

1 Code Block
DATA STEP Data
Explanation :
Creation of the LENGTH_DATA table. Reads a 30-character string and calculates its length using different functions (length, lengthn, lengthc, lengthm).
Copied!
1DATA LENGTH_DATA;
2 INPUT a $CHAR30.;
3 b=LENGTH(a);
4 c=lengthn(a);
5 d=lengthc(a);
6 e=lengthm(a);
7 DATALINES;
8Pra deep Sathyamurthy
9;
2 Code Block
PROC PRINT
Explanation :
Display of results to compare the values returned by the different length functions.
Copied!
1PROC PRINT;
2 var a b c d e;
3RUN;
4QUIT;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.