ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 16

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 = '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)
Click Comment link to get answer

54 comments:

  1. Anonymous2:58 AM

    D. . (missing numeric value)

    ReplyDelete
  2. C as there is no @ after the input the pointer will move to age 7-8 and the out put 40 for age

    ReplyDelete
  3. Anonymous11:57 PM

    The answer is C (40). Here is my program:
    data employee;
    input name $ 1-4;
    if name = 'Sue' then input age 7-8;
    else input idnum 10-11;
    cards;
    Ruth 39 11
    Jose 32 22
    Sue 30 33
    John 40 44
    ;
    run;
    proc print data=employee;
    run;

    ReplyDelete
  4. Anonymous9:23 PM

    Answer should be D(missing); question talks about when the conditon is "sue" and not the program output

    ReplyDelete
  5. Anonymous9:46 AM

    Anyone can exaplain me which is the right answer and why? Please. Thanks

    ReplyDelete
  6. Mac: Answer is C because after reading following statement

    input employee_name $ 1-4;

    SAS advances to next line of raw data file and next input statement

    if employee_name = 'Sue' then input age 7-8;

    reads age for John as age of SUE which is 40. Hopefully that will help.

    ReplyDelete
    Replies
    1. Anonymous11:11 PM

      Ok

      Delete
    2. can you please explain more clearly or any other way? i am not getting this

      Delete
  7. Anonymous12:25 PM

    I thougth answer is D but I am not sure anymore after running the above script given by Anonymous. It gives the output:

    Obs name age idnum
    1 Ruth . 2
    2 Sue 0 .
    An thus I am even more puzzled. Any ideas?

    ReplyDelete
    Replies
    1. Anonymous1:14 AM

      becuase, the original data set of this Question is
      Ruth 39 .....!! that reads 7-8 column right way..
      there is double-spaced blanks between Ruth and 39.

      Delete
  8. Anonymous3:57 PM

    Its the 0 from 40 as, if employee_name='Sue' then input age 7-8 so, at 7 it is 0 not 40;

    ReplyDelete
  9. Anonymous2:04 PM

    I have the same result running the code given above
    1 Ruth . 2
    2 Sue 0 .
    Would the 0 from 03 b/c
    if employee_name='Sue' then input age 7-8
    if you count the position for the obs starting with "Sue" the column 7-8 would result in 03. Can someone explain why the output has 3 obs: Ruth and Sue?

    ReplyDelete
  10. Age is read only for sue, for all other observation idnum is read. So in output you will have 3 observations.

    ReplyDelete
    Replies
    1. Anonymous9:40 PM

      No...First of all the spacing given in the data sets are inaccurate.
      Secondly even if you correct them and run the program you only get 2 observations and 3 variables.
      Please check and confirm.

      Delete
  11. The o/p have 3 variables and 2 observations

    employee_name, age and idnum for each observation..

    ReplyDelete
  12. swapna8:28 PM

    the answer is D.

    To get the correct result
    data test;
    infile employee;
    input employee_name $ 1-4 @;
    if employee_name = 'Sue' then input age 6-7;
    else input idnum 8-10;
    run;
    proc print;
    run;

    ReplyDelete
  13. data employee;
    input name $ 1-4;
    if name = 'Sue' then input age 7-8;
    else input idnum 10-11;
    cards;
    Ruth 39 11
    Jose 32 22
    Sue 30 33
    John 40 44
    ;
    run;
    proc print data=employee;
    run;

    output is :


    obs name age idnum
    1 Ruth . 22
    2 Sue 40 .

    ReplyDelete
  14. Anonymous6:24 AM

    The correct answer should be '0'.

    Here is the output:
    Obs name age idnum
    1 Ruth . 2
    2 Sue 0 .

    cheers
    ferrat

    ReplyDelete
  15. Moses1:08 AM

    When I debug the program:

    43 data employee /debug;
    44 input name $ 1-4;
    45 if name = 'Sue' then input age 7-8;
    46 else input idnum 10-11;
    47 cards;

    ===================================
    = Begin of debug
    ===================================

    DATA STEP Source Level Debugger

    Stopped at line 44 column 1
    >
    Stepped to line 45 column 1
    >
    Stepped to line 46 column 6
    > e name
    name = Ruth
    >
    Stepped to line 47 column 1
    > e idnum
    idnum = 2
    >
    Stepped to line 44 column 1
    >
    Stepped to line 45 column 1
    > e name
    name = Sue
    > e age
    age = .
    >
    Stepped to line 45 column 22
    > e age
    age = .
    >
    Stepped to line 47 column 1
    > e age
    age = 0
    > e name
    name = Sue
    > e idnum
    idnum = .
    >
    Stepped to line 44 column 1
    > e name
    name =
    >
    The DATA STEP program has completed execution
    > e age
    age = .
    > e idnum
    idnum = .

    ===================================
    = End of debug
    ===================================
    Zero value from var age is reading from line number 4 (John 40 44) column no 7 which is 0

    It mean condition :
    if name = 'Sue' then input age 7-8;
    is granted eventhou length of name is $ 1-4 (4 characters)

    ReplyDelete
  16. Anonymous12:54 PM

    I'm also getting the output of below; so I would have to make an educated guess. Why do we get so many varying answers among us?

    Obs name age idnum
    1 Ruth . 2
    2 Sue 0 .

    ReplyDelete
  17. Anonymous4:11 PM

    i think the answer is D.

    ReplyDelete
  18. Anonymous12:06 PM

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

    let me copy the question and output for u guys

    Which one of the following values does the variable AGE contain when the name of the employee is "Sue"?

    Output:
    Obs name age idnum
    1 Ruth . 2
    2 Sue 0 .

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

    1. 0 is not an option in the given options
    2. SAS never reads 40 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 SUE, WHAT DOES THE VAR AGE CONTAINS?

    AFTER PDV COMPLETED ON OBSERVATION
    RUTH . 2
    NAME was RUTH and AGE was .
    SO NEXT PDV STARTED
    INPUT NAME $ 1-4
    VAR NAME was read as SUE ****NOW JUST STOP***
    THE QUESTION IS ABOUT THIS MOMENT NOT OUTPUT
    AT THIS MOMENT VAR NAME CONTAINS SUE
    VAR AGE CONTAINS . A MISSING VALUE.

    REST PROCESS
    IT GOES TO NEXT LINE THE IF STAT, CHECK THE CONTION THEN READS FOURTH LINE OF RAW DATA AT COLUMN 7-8, WHICH IS '0'
    VAR AGE MISSING VALUE IS REPLACED BY 0 THUS THE OUTPUT IS ZERO.

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

    ReplyDelete
  19. Anonymous8:01 PM

    in this program you will never get the cond if employee_name = 'Sue' as true because sas reads it
    for idnum for the 1st record.it goes to next line and read john for the employee_name .so effectively it never reads sue as emloyee_name.

    ReplyDelete
  20. Anonymous8:44 PM

    i think the answer is D, becoz when "Sue" is read the data stored in PVD will be "Sue " as name
    $ 1-4.
    So when the employee name is Sue , name="Sue" is not true thus the if loop will not process

    ReplyDelete
  21. Anonymous9:42 PM

    Sakar Sham;
    Answer sheet ; "B" = 33 ? no clue. Seems need more conceptual and logical base.

    ReplyDelete
  22. Anonymous3:07 PM

    Folks , I put the data nicely to fit ( fixed column )

    NO matter whose name you put, there is always two names " Ruth and Sue " in the output.
    What is the reason it is not looking anything else or generating other thing???????????
    I am puzzled!

    ReplyDelete
  23. Anonymous9:50 AM

    are we saying it's missing value becasuse the output will be "0_" (with a space)
    and since, space is not a stanrard numeric value
    it will result in Missing value?

    ReplyDelete
  24. Anonymous10:45 AM

    . The data it is not align with 7-8 and 10-11 column in the external file. In this case the answer is D) Missing value.
    . if you align the columns to 6-7 and 9-10 the answer is b)40.
    . Cards or datalines don't behave the same as to read an external file. Why I don't know.
    . You get just 2 records (Ruth and Sue), because it doesnt have trailing option @, for the first row read 2 times, the get Sue row and read it 2 times. so the other records are lost

    ReplyDelete
  25. Behind the schenes:
    1)input loads the buffer with Ruth 39 11.
    2) ruth is tested and false and the pointer goes back to the top of the data step.
    3) same process with jose
    4)Sue: the buffer is loaded with Sue 30 33
    a) Sue is written (input name $ 1-4). Sue is tested and true(if employee_name=Sue) "then input" loads the observation of John because no @.
    b)As the pointer is on the obs of john, the pointer finds 40 on age 7-8.
    therefore the PDV will release:
    Name Age IBNUM
    Sue 40 .

    Hope you guys understand!

    ReplyDelete
    Replies
    1. Anonymous1:56 PM

      Excellent explanation. Thank you.

      Delete
  26. Anonymous10:00 PM

    i'd agree with this below

    Anonymous9:50 AM

    are we saying it's missing value becasuse the output will be "0_" (with a space)
    and since, space is not a stanrard numeric value
    it will result in Missing value?

    ReplyDelete
  27. Anonymous5:41 AM

    I' all so test it, and get answer D.
    Below is my test...


    employee_
    name age idnum

    Ruth . .

    ReplyDelete
  28. Anonymous10:33 AM

    Ans is D.

    Guys the data is "variable field raw data". Hence the program in the Q. would pick up a missing value in the age => therefore when 'sue" is read by SAS the age value is "."

    Now to get the desired output run the following program:

    data sue;
    infile "practice";
    input employee_name $ 1-4 @ ;
    if employee_name = 'Sue' then input age 8-9;
    else input idnum 10-11;
    run;

    ReplyDelete
  29. It is C, page 9 of the following doc explains in detail

    http://www2.sas.com/proceedings/sugi29/253-29.pdf

    ReplyDelete
    Replies
    1. You can test using the following code. Run without the @ in the input line, then uncomment and run again.

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

      Delete
  30. Anonymous4:40 AM

    Answer is D, Input loads first record, if statement is false, else input loads second record, and reads from columns 10-11, however the record is 10 columns long and so sas by default (flowover) will load the next record (sue). Nothing from this record is outputted.

    ReplyDelete
  31. Anonymous12:08 PM

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

    The answer is C.
    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
  32. C, the tricky thing to watch here is that name and age have to blanks in between them

    ReplyDelete
  33. Anonymous4:07 PM

    I found the original question here, there is something wrong with the display so that you guys argue about the answer. Here: http://sas.1or9.com/archives/sas-certified-base-programmer-123-questions-109/
    And now it's clear that the answer is C.

    ReplyDelete
  34. Anonymous6:37 PM

    gm;;
    c

    ReplyDelete
  35. Anonymous12:52 PM

    Answer is zero in this case when the name = Sue , the pointer will move to John and read 0 (of 40) and space at the position 7-8.

    ReplyDelete
    Replies
    1. Anonymous10:01 AM

      This is the correct answer and for the right reasons.

      Just run the program for yourself to check it.

      Delete
  36. Jenine4:02 PM

    Answer is really mean to be C (40)

    The way this question was posted on the blog is wonky which is making everyone confused. True, the way that it was posted here the actual value will be 0 because it is picking up only the final 0 from the 40 on line 4.

    Since there is no option for the answer to be 0, we know that there is something wrong with the way the question has been copied and pasted in this blog post.

    However, it is supposed to be written with two spaces between the name and age, so that the age actually appears in columns 7 and 8.

    This is the problem with studying from dodgy blog posts...unfortunately I have found many have errors like this, which makes it nearly impossible to figure out if you've got it right or not.

    Buy the real SAS practice exam, and take the rest with a grain of salt and/or common sense I spose!

    ReplyDelete
  37. Anonymous11:05 PM

    This is very confusing! Note that employee_name = 'Sue' has only THREE characters. Strictly speaking, there should be no match and no date AGE value should be read. BUT somehow SAS ignores the trailing white spaces when comparing string values.
    CAN SAS standardize it's language?

    ReplyDelete
  38. Please try program in SAS before you post answers here.... B is right answer.
    gclub
    gclub casino online

    ReplyDelete
  39. Your blog is very useful for me.I really like you post.Thanks for sharing.

    ทองดีฟันขาว

    ReplyDelete
  40. C is the answer. It is bcz: since @ is not used, the data pointer will come to the second record instead of staying at the first. Then the condition is checked and failed, so it fills the id number from column 10-11 (value: 22). next it reiterates from the 3rd record where employee_name is "Sue" but it jumps to 4th record as no @ used. However, the If condition is satisfied hence the age is read from column 7-8 of 4th record (Value: 40)

    ReplyDelete