Published on :
Data Manipulation INTERNAL_CREATION

Removing left spaces with the LEFT function

This code is also available in: Deutsch Español Français
Awaiting validation
This script creates a temporary table named 'lead' containing character strings with varying indentations. It uses the LEFT function within a Data Step to left-align the text by removing initial spaces. The result is displayed using the PRINT procedure with specific formatting to visualize the strings before and after processing.
Data Analysis

Type : INTERNAL_CREATION


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

1 Code Block
DATA STEP Data
Explanation :
Creation of the 'lead' dataset and application of the LEFT function on the 'string' variable to create the 'left_string' variable without leading spaces.
Copied!
1DATA lead;
2INPUT string $15.;
3left_string = Left(string);
4DATALINES;
5ABC
6 XYZ
7 Ron Cody
8;
2 Code Block
PROC PRINT
Explanation :
Displaying data from the 'lead' table to compare the original and processed strings. Using the $quote17. format to visualize string boundaries.
Copied!
1PROC PRINT DATA=lead noobs;
2title"Left_funct";
3FORMAT string left_string $quote17.;
4RUN;
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.