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;
Share Share Tweet