By admin | September 23, 2009

SAS Certified Base Programmer 123 Questions (76)

The following SAS program is submitted:

data work.test;
    Author = 'Agatha Christie';
    First = substr(scan(author,1,' ,'),1,1);
run;

Which one of the following is the length of the variable FIRST in the output data set?

A. 1
B. 6
C. 15
D. 200

13 comments | Add One

  1. admin - 09/23/2009 at 9:37 am

    D

  2. geoff davis - 02/15/2010 at 10:13 pm

    I’m getting A as the answer to Q76 – could you check please?
    scan(author,1,’ ,’) returns Agatha
    substr(agatha,1,1) returns A
    Length First = 1

  3. geoff davis - 02/15/2010 at 10:21 pm

    Apologies – error in my LENGTH calcs. The length of FIRST is indeed D – 200

  4. admin - 03/12/2010 at 7:42 pm

    @3. geoff davis Thanks for your comments here…Everyone makes mistakes…:-)

  5. Chris - 07/23/2010 at 4:44 am

    I still don’t know why the answer is 200.
    Could someone explain for this?

  6. admin - 07/28/2010 at 2:42 pm

    @ 5 Chris, Install SAS, and run the code…..

  7. JG - 07/25/2010 at 10:14 pm

    Got the same mistake as Geoff davis, I think.
    By using Length() function, the length is 1.
    By using Proc Contents data=test, the length is 200.

  8. Chris - 08/13/2010 at 5:24 am

    200 is the SAS default length for Char functions.

  9. sameer - 04/21/2011 at 6:31 am

    lenghth 200 is the default length for scan function and not for every character function.

  10. Mina Zhou - 03/4/2012 at 4:43 pm

    I also get different length using PROC CONTENTS and LENGTH(). so which one should be the answer…?

  11. Mina Zhou - 03/4/2012 at 4:50 pm

    Oh I see. LENGTH() excludes trailing blanks. LENGTHC() gives the same length as the PROC CONTENTS.

  12. Satya Nukala - 09/24/2012 at 12:06 pm

    length function returns the length of the argument after removing trailing blanks.It does not give the actual lenth.
    Leading and blanks in between are counted towards the length.

  13. neeru - 03/28/2014 at 6:51 am

    the length of character target variable is always 200 bytes long

Leave a Comment

Leave a Reply

Your email address will not be published.