x
Need help studying for the new
SAS Certified Specialist Exam?
SAS Certified Specialist Exam?
Get access to:
- Two Full Certificate Prep Courses
- 300+ Practice Exercises
|
Lesson 6.2: Trim & Compress
IMPORTANT! We have recently updated our training materials. Check out the latest free training here.
Example
In this dataset, we have two variables: Student Name and Phone Number. The code below will show you the TRIM and COMPRESS functions work:
DATA Student2; Set Student; Phone_Trimmed = Trim(Phone); Phone_Compressed = COMPRESS(Phone); RUN; Now, let's take a look at the Student2 dataset in the Proc Print output. Proc Print output lets you view the data in the output window.
As you can see, the COMPRESS function works according to our description above - to trim all the white space from the variable. The Phone_Compressed variable compresses the original Phone variable and removes all the white spaces between the numbers.
However, the newly created Phone_Trimmed variable remains unchanged from the original Phone variable! This is because the TRIM function removes the white space at the END of the variable. There is no white space to be removed there in the Phone variable. Let’s use another example to see the effect of the TRIM function. Example
DATA Student3; Set Student; Info1 = First || Last; Info2 = TRIM(First) || Last; RUN; In this example, the double stroke ( || ) is used to combine the different texts into one variable. Both Info1 and Info2 combine the First and Last Name into one text. Again, Let's take a look at the output: As you can see, Info2, with the TRIM function, eliminates the white space at the end of the First variable.
DONE! You have learned the TRIM and COMPRESS functions in SAS! Note:
|
|