By admin | August 10, 2009

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

3 comments | Add One

  1. admin - 08/10/2009 at 10:01 am

    D

  2. Chris - 08/10/2009 at 1:43 pm

    Shouldn’t the trim funcation trim the length to 4?

  3. admin - 08/10/2009 at 3:41 pm

    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.

Leave a Comment

Leave a Reply

Your email address will not be published.