Practical SAS Training Course for Beginners
Get Access to:
|
x
Need help studying for the new
SAS Certified Specialist Exam?
SAS Certified Specialist Exam?
|
Trim FunctionHow to Remove Trailing Spaces From Character ValuesThe TRIM function is used to remove trailing spaces from character values. It is usually used when concatenating variables. Example The data set above contains 2 columns: VAR1 and VAR2. Both variables have a length of 10: You can create the data set using the code below:
data string; length var1 var2 $ 10; input var1 $ var2 $; datalines; ABC DEF abc def 1234 5678 ; run; Remove Trailing Spaces from TextWhen concatenating variables in SAS, you might get unwanted spaces between the values being combined. Example data string2; set string; comb = var1 || var2; run; The VAR1 and VAR2 variables are concatenated into the COMB variable. There are blank spaces between the two values: The blank spaces come from the trailing spaces from the VAR1 variable. You can use the TRIM function to remove them: Example data string2; set string; comb = trim(var1) || var2; run; The TRIM function removes the trailing spaces from the VAR1 variable. The character values are concatenated with the unwanted spaces removed: Are you totally new to SAS?
Take our Practical SAS Training Course for Beginners and learn how to code your first SAS program!
|
|