ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 15

The contents of the raw data file EMPLOYEE are listed below:
--------10-------20-------30
Ruth 39 11
Jose 32 22
Sue 30 33
John 40 44
The following SAS program is submitted:
data test;
infile 'employee';
input employee_name $ 1-4;
if employee_name = 'Ruth' then input idnum 10-11;
else input age 7-8;
run;
Which one of the following values does the variable IDNUM contain when the name of the employee is "Ruth"?
A. 11
B. 22
C. 32
D. . (missing numeric value)
Click Comment link to get answer

62 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Should this be B? as I think it should be "D" . Please post your comment

    ReplyDelete
  3. Anonymous6:07 AM

    Its B

    ReplyDelete
  4. Anonymous7:41 PM

    Answer should be D. Check out.

    ReplyDelete
  5. Anonymous5:27 PM

    yeap i agree answer is D

    ReplyDelete
  6. Anonymous4:27 PM

    answer is b

    ReplyDelete
  7. Anonymous9:56 AM

    Answer is 22.

    This is a free listing format and the cursor moves to the second record and picks up 22.

    The answer is B

    ReplyDelete
    Replies
    1. Anonymous10:01 PM

      True. The column numbering is incorrect.
      But B is correct answer.

      Delete
  8. Anonymous1:56 AM

    Answer is D

    ReplyDelete
  9. Anonymous7:20 PM

    Answer is B

    ReplyDelete
  10. Anonymous7:19 PM

    if you run the program as it is the answer should be and is '2' but if you change the position of idnum to 9-10, then the answer is 22.

    b is the best among the choices given.

    ReplyDelete
    Replies
    1. Anonymous11:02 AM

      yes,agree with Yogesh

      Delete
    2. Absolutely this one would be '2'. They should modify the question.

      Delete
  11. Anonymous7:19 PM

    This comment has been removed by the author.

    ReplyDelete
  12. Anonymous5:44 PM

    Seems like answer is D after all. Here is my log:
    Invalid data for idnum in line 3 1-2.
    RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9--
    3 Sue 30 33 9
    employee_name=Ruth idnum=. age=. _ERROR_=1 _N_=1
    NOTE: LOST CARD.
    employee_name=John idnum=. age=. _ERROR_=1 _N_=2
    NOTE: 4 records were read from the infile EMPL.
    The minimum record length was 9.
    The maximum record length was 10.
    NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
    NOTE: The data set WORK.TEST has 1 observations and 3 variables.

    ReplyDelete
  13. Anonymous8:59 AM

    ANSWER IS D, I CHECKED

    ReplyDelete
  14. The answer is B......
    As the pointer moves to next column when its checks the condition....
    The output would be

    employee_name idnum age
    Ruth 22 .
    Sue . 0(the zero value is of John age 40)

    ReplyDelete
  15. The correct ans in this case is C.

    if a trailing '@'is used in input statement {which was supposed to be}then it would give the value 39.


    C - correct ans

    any doubt ?

    ReplyDelete
  16. Anonymous4:02 PM

    answer is B

    run the program:

    data employee;
    input employee_name $ 1-4;
    if employee_name = 'Ruth' then input idnum 9-10;
    else input age 6-7;
    datalines;
    Ruth 39 11
    Jose 32 22
    Sue 30 33
    John 40 44
    ;
    run;

    ReplyDelete
  17. Anonymous7:20 AM

    the answer is d. try the above program but don't use datalines, copy the datalines to a text file and run the program in the question. The txt file behaves differently than the datalines.

    ReplyDelete
  18. Answer is D.

    data test;
    infile 'C:\Documents and Settings\pach\Desktop\employee';
    input employee_name $ 1-4;
    if employee_name = 'Ruth' then input idnum 10-11;
    else input age 7-8;
    run;

    Log file reads

    The SAS System 21:18 Monday, August 25, 2008 1

    employee_
    Obs name idnum age

    1 Ruth . .

    ReplyDelete
  19. Proudy7:45 AM

    The Answer is D.

    Why? Simple.

    after 'ruth' is input the next line is read for the if/else cond. since it is true SAS reads in the data in cols 10-11. however the record length is 10 so it skips to the next line and grabs the 'S' from Sue. this gives ID a missing value because its not numeric.

    to get the desired output a trailing @ is required to hold the line for the if/then cond. and the cols spec. needs to be changed:

    data test;
    infile 'employee';
    input employee_name $ 1-4 @;
    if employee_name = 'Ruth' then input idnum $ 9-10;
    else input age $ 5-7;
    run;

    ReplyDelete
    Replies
    1. Anonymous5:10 PM

      nice1

      Delete
    2. Exactly.
      Just to clarify, before reaching the end of record, the pointer is on position 10 and grabs the last 2 of Jose's age of 22, then moves to the next observation and for position 11 it picks up the 'S' from Sue, making the record '2S'. SAS flags the error and stops processing because '2S' is not numeric.

      Delete
  20. Anonymous10:38 AM

    Think this question would make more sense if the raw data file was like this:

    ---------10--------20--------30
    Ruth 39 11
    Jose 32 22
    Sue 30 33
    John 40 44

    Then the answer would be B. I agree with Yogish that the answer to the actual question given is '2' (if we neglect that the number line is labelled incorrectly).

    ReplyDelete
  21. Anonymous10:41 AM

    Sorry i'll post that again:

    ---------10--------20--------30
    Ruth~~39~11
    Jose~~32~22
    Sue~~~30~33
    John~~40~44

    ReplyDelete
  22. Anonymous10:56 AM

    The answer is D.

    After submitting the raw data file, this is view in the SAS Log:

    NOTE: Invalid data for idnum in line 3 1-2.
    RULE:
    ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+-

    3 Sue 30 33 9

    employee_name=Ruth idnum=. age=. _ERROR_=1 _N_=1

    NOTE: 6 records were read from the infile EMPLOYEE.

    The minimum record length was 0.
    The maximum record length was 10.

    NOTE: SAS went to a new line when INPUT statement reached past the end of a line.

    NOTE: The data set WORK.EMPLOYEE has 2 observations and 3 variables.

    The Output displays:

    employee_ name idnum age
    Ruth . .
    John . .

    ReplyDelete
  23. Anonymous9:46 PM

    Definitely B.Run the following:
    data test;
    input employee_name $ 1-4;
    if employee_name = 'Ruth' then input idnum 10-11;
    else input age 7-8;
    put idnum= age=;
    cards;
    Ruth 39 11
    Jose 32 22
    Sue 30 33
    John 40 44
    ;
    run;

    ReplyDelete
  24. Anonymous3:35 AM

    neither A-D

    ReplyDelete
  25. Anonymous4:25 AM

    Can you explain WHY does this dataset have only 2 observations? Thanks

    data employee;
    input employee_name $ 1-4;
    if employee_name = 'Ruth' then input idnum 9-10;
    else input age 6-7;
    datalines;
    Ruth~39~11
    Jose~32~22
    Sue~~30~33
    John~40~44
    ;
    run;

    And dataset employee looks like:
    employee_
    name idnum age
    Ruth 22 .
    Sue . 40

    ReplyDelete
  26. Anonymous1:31 PM

    guys common, 2 is not in the option and 22 cant be the answer either for 2 reasons
    1. 22 starts fr column 6-7 thus the output is 0
    2. question is not abt output in ruth's observatn

    let me copy the question and output for u guys

    Which one of the following values does the variable IDNUM contain when the name of the employee is "Ruth"?


    Output:(if u run the program as it is)
    Obs name idnum age
    1 Ruth 2 .
    2 Sue . 0

    So the answer is D (missing value) for 3 reason

    1. 2 is not an option in the given options
    2. SAS never reads 22 as it is not in any variables range.
    3. THE ONLY AND MOST IMPORTANT- SEE THE QUESTION- IT IS ASKING WHEN VARIABLE 'NAME'(employee name) IS ruth, WHAT DOES THE VAR IDNUM CONTAINS?

    WHEN PDV STARTED ON FIRST OBSERVATION IT WAS LIKE THIS
    emp_name idnum age
    . .
    after first input stat for emp_name pdv was like
    emp_name idnum age
    ruth . .

    So the question is about this moment not abt output, as we all know what we r getting as output

    at this moment idnum is .(missing value)

    and so on the process continues, it jumps to second data line(due to ; in input stat), checks condition, condition is true reads 0 from column range 7-8 from second raw data line and continues so on to get the above mentioned output

    THIS WAS A TRICKY QUESTION, SO THE ANSWER WAS IN THE QUESTION. THATS WHY THEIR IS NOT UNANIMOUS RESULTS.

    This is the only logic which get u the result available in the options without changing the program or raw data column position.

    I dont think their is any mistake in question or raw data position as the next question is uses the same program and data. This is on purpose. HOPE THIS HELPS.

    ReplyDelete
  27. Anonymous11:21 AM

    Sakar;
    I found this question with answer; But it is asked differently.
    Question: 67
    The contents of the raw data file EMPLOYEE are listed below:
    ----|----10----|----20----|----30
    Ruth 39 11
    Jose 32 22
    Sue 30 33
    John 4044
    The following SAS program is submitted:
    data test;
    infile ‘employee’;
    input employee_name $ 1-4;
    if employee_name = ‘Sue’ then input age 7-8;
    else input idnum 10-11;
    run;
    Which one of the following values does the variable AGE contain when the name of the employee
    is “Sue”?
    A. 30
    B. 33
    C. 40
    D. (missing numeric value)
    Answer: B

    Now , is this going to change your answer so far you have given, I mean is your logic will alter and come different answer.
    Thank you.
    Sakar

    ReplyDelete
    Replies
    1. Anonymous4:30 AM

      Nope, the answer is "C".

      The SAS System

      Obs NAME AGE ID

      1 RUTH . 22
      2 SUE 40 .

      Delete
  28. Anonymous1:20 AM

    answer is D for sure I agree with Proudy...

    ReplyDelete
  29. Anonymous6:10 AM

    can somebody please explain why the pointer would move down the row to check the condition?

    I've wasted an hr and am no where close on figuring out.

    for my understanding,
    b/c data step is done per observation, shouldn't the poniter remain in the same row untill the end of the data step?
    and therefore, with 1st observation being
    Ruth 39 11
    shouldn't it return whatever is on column 10 and 11 of the first observation?

    THX IN ADVANCEEEE

    ReplyDelete
    Replies
    1. you need the single trailing @ so it could remain in the same row :)

      Delete
  30. Anonymous3:16 PM

    I have give this problem to an university teacher and will post it as I get the reason behind.

    ReplyDelete
  31. Anonymous8:29 PM

    We don't have @ at the end of first input statment, so input pointer will move to next line in raw data. So after reading employee_name= "ruth" pointer is at second raw record. Our if statment yeilds true, so second input statment reads 22 for IDNUM. Again we don't have @ at the end of second input statement too, so pointer is on thrid raw record. Now SAS reads "Sue" for employee_name and pointer moves to next raw record. If statement yeilds false and else input statment will read 40 for age.
    Hope this helps.

    ReplyDelete
    Replies
    1. Anonymous2:49 PM

      Thank you, this is the only explanation that made sense.

      Delete
    2. Anonymous3:26 PM

      i agree!

      Delete
  32. Anonymous2:56 AM

    wats the final answer??

    ReplyDelete
  33. C is correct, align the raw data as per ruler,
    --------10-------20-------30
    Ruth 39 11
    Jose 32 22
    Sue 30 33
    John 40 44

    ReplyDelete
  34. Anonymous5:16 PM

    it's c god you guys are dumb

    ReplyDelete
  35. Anonymous11:59 AM

    data test;
    infile datalines;
    input employee_name $ 1-4;
    if employee_name = 'Ruth' then input idnum 10-11;
    else input age 7-8;
    datalines;
    Ruth 39 11
    Jose 32 22
    Sue 30 33
    John 40 44
    run;

    The answer is B.
    No trailing @ after the first input, so the idnum/age value is read from the line below. Ruth has Jose's idnum of 22 (one line down) (missing age), because the if/then is true. If we keep going, the next name read in is Sue with Johns age (because the if/then is false) of 40 (missing idnum).

    ReplyDelete
    Replies
    1. Anonymous12:02 PM

      You can't really see it but the datalines are:
      Ruth<2spaces>39<1space>11
      Jose<2spaces>32<1space>22
      Sue<2spaces>30<1space>33
      John<2spaces>40<1space>44

      I did this to match the column inputs.

      Delete
  36. Anonymous6:23 PM

    gm;;;;

    D

    ReplyDelete
  37. Anonymous10:16 PM

    Please try program in SAS before you post answers here.... B is right answer

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

    ReplyDelete
  39. data test;
    input employee_name $ 1-4;
    if employee_name = 'Ruth' then input idnum 10-11;
    else input age 7-8;
    datalines;
    Ruth 39 11
    Jose 32 22
    Sue 30 33
    John 40 44
    ;
    run;

    the value of idnum is 2 where employee_name is 'Ruth';

    ReplyDelete
    Replies
    1. Anonymous9:42 PM

      To Nayan,

      I'm getting the same answer when I run the code and just reading from columns 10-11 of the second input line.

      Delete
  40. Anonymous6:30 PM

    I initially thought "how could this be anything but D?" Then I ran the code (it's B - 22). Without trailing @-signs, each input statement progresses the PDV down one record. Therefore, the PDV reads in Ruth for employee_name. The condition that employee_name = Ruth holds, thus the input statement for idnum occurs. But there was no trailing @ to hold the input to the same record, so the PDV goes down to the next line to read in idnum = 22. The else statement doesn't happen so there is nothing read into age. It reaches the end of the data step, and by default outputs the observation: 'Ruth 22 .'. (The PDV order is name-id-age).

    To check this, take out the if/then statements and just run the data step with three input statements in a row - Ruth 22 30. Each input starts on the next record.

    This was under the assumption that the data was poorly copied here, and that age does start at column 7 and idnum at column 10. Otherwise, it would give 2 for idnum.

    ReplyDelete
    Replies
    1. The only useful explanation. Thanks so much!

      Delete
  41. Answer B

    ReplyDelete
  42. Very nice post.really I apperciate your blog.Thanks for sharing.keep sharing more blogs.

    ทองดีฟันขาว

    ReplyDelete