STRIP Function in SAS : Remove Spaces from String

Deepanshu Bhalla Add Comment

In SAS, the STRIP function removes both the leading and trailing spaces from a string or character variable. It is equivalent to MS Excel's TRIM Function.

Please note that the STRIP function does not remove spaces between words. Use COMPRESS function instead if you want to remove spaces between words.

The syntax of STRIP function is as follows:

new_variable = strip(variable)
Sample Dataset

Let's create a sample SAS dataset for demonstration purpose.

data example;
input name $char20.;
cards;
    David Sandy 
   Sam Andrews
;
run;

The following code creates "result" dataset that stores the same observations as the "example" dataset, but with an additional variable called "name_clean" that stores the cleaned version of the "name" variable, removing any leading or trailing spaces.

data result;
set example;
name_clean = strip(name);
run;
STRIP Function in SAS
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 0 Response to "STRIP Function in SAS : Remove Spaces from String"
Next → ← Prev