ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 56

The following SAS DATA step is submitted:
data work.accounting;
set work.department;
length jobcode $ 12;
run;
The WORK.DEPARTMENT SAS data set contains a character variable named JOBCODE with a length of 5.
Which one of the following is the length of the variable JOBCODE in the output data set?
A. 5
B. 8
C. 12
D. The length can not be determined as the program fails to execute due to errors.
Click Comment link to get answer

15 comments:

  1. A. is correct

    This is the log error after we run this program.

    /* WARNING: Length of character variable has already been set.
    Use the LENGTH statement as the very first statement in the DATA STEP to declare the length
    of a character variable.
    */

    ReplyDelete
  2. Anonymous1:37 PM

    Answer is A

    ReplyDelete
  3. Anonymous4:09 PM

    Note:
    If the "length statement" would have been defined before "set statement", then the answer would be C!

    ferrat

    ReplyDelete
  4. Moses4:58 AM

    The correct answer is A:

    Pls see program below:

    data work.department;
    jobcode = '12345';
    run;

    data work.accounting;
    set work.department;
    length jobcode $ 12;
    jobcode = '123456789012';
    run;

    proc contents data=work.accounting;
    run;

    ==============================
    = Begin of SAS log
    ==============================
    214 data work.department;
    215 jobcode = '12345';
    216 run;

    NOTE: The data set WORK.DEPARTMENT has 1 observations and 1 variables.
    NOTE: DATA statement used (Total process time):
    real time 0.14 seconds
    cpu time 0.02 seconds


    217
    218 data work.accounting;
    219 set work.department;
    220 length jobcode $ 12;
    WARNING: Length of character variable jobcode has already been set.
    Use the LENGTH statement as the very first statement in the DATA STEP to declare the
    length of a character variable.
    221 jobcode = '123456789012';
    222
    223 run;

    NOTE: There were 1 observations read from the data set WORK.DEPARTMENT.
    NOTE: The data set WORK.ACCOUNTING has 1 observations and 1 variables.
    NOTE: DATA statement used (Total process time):
    real time 0.08 seconds
    cpu time 0.03 seconds


    224
    225 proc contents data=work.accounting;
    226 run;

    NOTE: PROCEDURE CONTENTS used (Total process time):
    real time 0.20 seconds
    cpu time 0.01 seconds

    ==============================
    = End of SAS log
    ==============================

    ==============================
    = Begin of SAS Output
    ==============================

    Alphabetic List of Variables and Attributes

    # Variable Type Len
    1 jobcode Char 5


    ==============================
    = End of SAS Output
    ==============================

    ReplyDelete
  5. Anonymous2:32 PM

    I tried it! it's C!!

    ReplyDelete
  6. Anonymous1:14 AM

    Its A because the base dataset has already the length set as 5 if you try to reset after set statement it gives you a warning.

    ReplyDelete
  7. Ans is A

    ReplyDelete
  8. It log window shown as warning but proc contets showing the length is 12.please correct me if i wrong...

    ReplyDelete
  9. Length of character variable jobcode has already been set.
    Use the LENGTH statement as the very first statement in the DATA STEP to declare the
    length of a character variable.
    Proc contens also showed length as 5: see belwo:
    The CONTENTS Procedure

    Data Set Name WORK.ACCOUNTING Observations 1
    Member Type DATA Variables 1
    Engine V9 Indexes 0
    Observation Length 5

    ReplyDelete
  10. Answer : A

    Reason : Sas defines the variable length in the descriptor portion of PDV through its first occurrence. In this case ,Set statement comes before Length therefore length = Length defined by the dataset being read by set statement.

    If we want to change that , Length statement must come before set statement so that it gets defined as 12 in descriptor portion.

    ReplyDelete
  11. This is making sense. Thanks.

    ReplyDelete