ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 55

The following SAS program is submitted:
data work.accounting;
set work.dept1 work.dept2;
run;
A character variable named JOBCODE is contained in both the WORK.DEPT1 and WORK.DEPT2 SAS data sets. The variable
JOBCODE has a length of 5 in the WORK.DEPT1 data set and a length of 7 in the WORK.DEPT2 data set.
Which one of the following is the length of the variable JOBCODE in the output data set?
A. 5
B. 7
C. 8
D. 12
Click Comment link to get answer

44 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. 'A'.
    The "set statement" takes the length of the common variable, as the length of that variable in the first dataset of set statement.

    ReplyDelete
  3. B is correct- If the data sets contain variables that have the same names, the values that are read in from the last data set overwrite the values that were read in from earlier data sets.

    ReplyDelete
    Replies
    1. Anonymous9:19 PM

      And that SAS is called ValSAS ? :-)

      Delete
  4. Anonymous10:43 PM

    Further clarification please

    ReplyDelete
  5. Anonymous10:53 PM

    Answer is A for sure.

    ReplyDelete
  6. Anonymous7:07 PM

    A for sure

    ReplyDelete
  7. Anonymous10:08 AM

    Answer is A.
    The length of a variable always define automatically in the first statement and remain unchanged during the whole program until and unless we redefine it.

    So when DEPT1 is set the lenght will set to 5 and remail unchanged during the data step.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  8. Anonymous2:22 AM

    correct answer is A

    ReplyDelete
  9. Anonymous1:31 AM

    Correct Answer is A.

    reason is length of the first placed dataset's variable's length will be taken, not the second placed.

    If set work.dept2 work.dept1;

    then the answer is 7.

    ReplyDelete
  10. C is correct.i juss run the program...
    data x;
    input jobcode:5.;
    datalines;
    12345
    123
    1098
    1234
    ;
    run;
    data y;
    input name$ jobcode:7.;
    datalines;
    aaa 102
    bbb 1234567
    ;
    run;
    data new;
    set x y;
    run;
    proc contents data=new;
    run;

    ReplyDelete
  11. Anonymous12:09 PM

    sorry..the above ans is correct only when JOBCODE is numeric var.

    ReplyDelete
  12. Anonymous2:38 PM

    Answer is A.
    Here is from SAS log:
    WARNING: Multiple lengths were specified for the variable jobcode by input data set(s). This may cause truncation of data.

    ReplyDelete
  13. souji u r wrong it should be character variable . u have put numeric one which will be 8 by default so ans is 5

    ReplyDelete
  14. Anonymous4:54 AM

    Answer is A
    data x;
    length jobcode 5;
    input jobcode:5.;
    datalines;
    12345
    123
    1098
    1234
    ;
    run;
    data y;
    length jobcode 7;
    input name$ jobcode:7.;
    datalines;
    aaa 102
    bbb 1234567
    ;
    run;
    data new;
    set x y;
    run;
    proc contents data=new;
    run;

    ReplyDelete
  15. midwesterner9:10 PM

    SASCERT, could you clarify please?

    ReplyDelete
  16. CHIRU2:38 AM

    A.... the length of a char var is fixed in work dataset1 and it takes same length while copying new value into it ....for example

    data try;
    a='asdfg';
    a='abcdefg';
    put @5 a;
    run;
    in log window we will find a value as abcde only 5 chars ...
    the char var takes first defined val length
    while numeric var by default it will take 12

    ReplyDelete
  17. chiru2:39 AM

    @ ani ...... u r right

    ReplyDelete
  18. Anonymous9:42 AM

    I tried it an get answer A

    ReplyDelete
  19. Anonymous8:40 AM

    data one;
    input jobcode $5. dept $3.;
    datalines;
    11111abc
    22222def
    33333xyz
    ;
    run;

    data two;
    input jobcode $7. dept $3.;
    datalines;
    1111117abc
    2222227def
    3333337xyz
    ;
    run;

    data three;
    set one two;
    run;
    proc print data=three;run;
    proc contents data=three;run;

    O/p:

    Obs jobcode dept

    1 11111 abc
    2 22222 def
    3 33333 xyz
    4 11111 abc
    5 22222 def
    6 33333 xyz


    contents:

    Alphabetic List of Variables and Attributes

    # Variable Type Len

    2 dept Char 3
    1 jobcode Char 5

    ReplyDelete
  20. Anonymous11:46 AM

    The answer is a and here is the correct version of Saujis program

    data x;
    input jobcode$5.;
    datalines;
    12345
    123
    1098
    1234
    ;
    run;

    data y;
    input name$ jobcode$7.;
    datalines;
    aaa 102
    bbb 1234567
    ;
    run;
    data new;
    set x y;
    run;

    proc contents data=new;
    run;

    ReplyDelete
  21. Anonymous7:36 PM

    The answer is C. Ran the program and it states the length is 8.

    data cc1;
    input job_code $;
    put @5 job_code;
    datalines;
    abcde
    ;
    run;

    data cc2;
    input job_code $;
    put @7 job_code;
    datalines;
    yuiophj
    ;
    run;

    data cc3;
    set cc1 cc2;
    run;

    proc contents data=cc3;
    run;

    Output:
    # Variable Type Len

    1 job_code Char 8

    ReplyDelete
    Replies
    1. Anonymous7:58 PM

      Sorry I realized I did this incorrectly. The answer is not C but should be A.

      Delete
  22. Ans is def A . If we do not specify length, then it be 8. there is no case of overwriting here since it is not interleaving (as there is no by statement) but concatenation only.

    ReplyDelete
  23. Anonymous7:18 PM

    here is the corrected program.
    since it is specified that jobcode is the numeric variable.


    data x;
    input jobcode $5.;
    datalines;
    aaaaa

    ;
    run;
    data y;
    input jobcode$7. ;
    datalines;
    sdssfdf
    ;
    run;
    data new;
    set x y;
    run;
    proc contents data=new;
    run;

    ReplyDelete
  24. This comment has been removed by the author.

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. A if jobcode is character variable.

    ReplyDelete
  27. what if its like set work.dept1 set work.dept2;

    ReplyDelete
  28. Answer : A
    Rules for Length Conflict Resolution in SAS
    a) When the length is explicitly defined in either of the dataset despite the position use that (not this scenario in Question)
    b) If Length is explicitly defined in both the datasets , then consider position. Length of first Dataset overrides others.

    ReplyDelete
  29. Anonymous9:24 PM

    correct answer is A


    ReplyDelete
  30. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.accounting and bookkeeping companie

    ReplyDelete
  31. Nice Blog, Thanks for sharing

    Team auditing company in uae and aroma oil

    ReplyDelete
  32. Interesting article. We are a leading audit firm in Dubai, UAE.

    ReplyDelete
  33. Are you looking for experts to help you obtain the general trading license in Dubai? then we are always ready to help you out. Get license to do business in UAE. 100% Legal assistance.

    ReplyDelete
  34. Company formation in SRTIP Free zone, the Sharjah Research, Technology and Innovation Park, offers a compelling opportunity for businesses. With a streamlined process and dedicated authorities, entrepreneurs can establish their companies efficiently. SRTIP Freezone provides a supportive ecosystem for research, technology, and innovation-driven enterprises, fostering collaboration with academia and government entities. Benefits include 100% foreign ownership, tax exemptions, state-of-the-art infrastructure, access to funding and venture capital, and a dynamic network of like-minded businesses. SRTIP Free zone supports diverse sectors such as technology, advanced manufacturing, renewable energy, and health sciences. Comprehensive support services, including legal assistance and visa facilitation, ensure a smooth setup. With its strategic location and incentives, SRTIP Free zone is an attractive choice for entrepreneurs looking to tap into the UAE's innovation ecosystem.

    ReplyDelete
  35. Nice blog post. I really enjoyed reading. Thanks for sharing. Keep posting.

    ReplyDelete