Transforming Data with SAS Functions | |
Modifying Character Values with
Functions![]() ![]() |
![]() |
The TRIM function enables you to remove trailing blanks from character values. |
General form, TRIM function:
where argument can be any character expression, such as
|
To remove the blanks from the variable NewAddress , include
the TRIM function in your assignment statement to trim the values of
Address and City .
data hrd.newtemp(drop=address city state zip); set hrd.temp; NewAddress=trim(address)||', '||trim(city)||', '||zip; run;
The revised DATA step creates the values that you expect for
|
SAS Data Set Hrd.Newtemp
NewAddress |
65 ELM DRIVE, CARY, 27513 |
11 SUN DRIVE, CARY, 27513 |
712 HARDWICK STREET, CHAPEL HILL, 27514 |
5372 WHITEBUD ROAD, RALEIGH, 27612 |
Points to Remember
Keep in mind that the TRIM function does not affect the way a variable is stored. Suppose you trim the values of a variable and then assign these values to a new variable. The trimmed values are padded with trailing blanks again if the values are shorter than the length of the new variable.
Here's an example. In the DATA step below, the new variable
data temp; set hrd.temp; length Street $ 20; Street=trim(address); run; |
Address length=32 |
Street length=20 |
65 ELM DRIVE···················· | 65 ELM DRIVE········ |
11 SUN DRIVE···················· | 11 SUN DRIVE········ |
712 HARTWICK STREET············· | 712 HARTWICK STREET· |
![]() ![]() ![]() ![]() ![]() ![]() |
|
![]() |
![]() |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.