SAS Certified Base Programmer 50 Questions (45)
The following SAS program is submitted:
data work.test; length city $20; city='Paris'; city2=trim(city); run;
Which one of the following is the length of the city2 variable?
a. 5
b. 6
c. 8
d. 20
Topics:
SAS Base Questions |
3 Comments »
D
Shouldn’t the trim funcation trim the length to 4?
The LENGTH statement specifies that the variable city has a length of 20 characters. The TRIM function in the assignment statement for city2 removes trailing blanks from the value. However, the length of the city2 variable is set to 20 because city has a length of 20, and SAS pads the trimmed value with extra blanks.
You can learn about
• the LENGTH statement in Reading Free-Format Data
• the TRIM function in Transforming Data with SAS Functions.