Master SAS in 30 days!

A jargon-free, easy-to-learn SAS base course that is tailor-made for students with no prior knowledge of SAS.

Strip Function: How to Remove Leading and Trailing Spaces from String

The STRIP function is similar to the TRIM function. It removes both the leading and trailing spaces from a character string.

Example

The data set above contains 2 columns: VAR1 and VAR2.

Both columns contain character values that have leading and trailing spaces.

The spaces become more obvious when the two variables are being concatenated:

data string2;
set string;
text = "@@" || var1 || var2 || "@@";
run;

You will see the leading and trailing spaces from both variables in the concatenated value:
Remove Leading and Trailing Spaces from Text
 
You can use the STRIP function to remove both the leading and trailing spaces from the character strings.

Example
 

data string2;
set string;
text = "@@" || strip(var1) || strip(var2) || "@@";
run;

The STRIP function is applied to both the VAR1 and VAR2 variables.

The character values are concatenated with the leading and trailing spaces removed:

Become a Certified SAS Specialist

Get access to two SAS base certification prep courses and 150+ practice exercises

Master SAS in 30 Days

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
iconmail

Get latest articles from SASCrunch

SAS Base Certification Exam Prep Course

Two Certificate Prep Courses and 300+ Practice Exercises