ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 46

The following SAS program is submitted:
data work.test;
Title = 'A Tale of Two Cities, Charles J. Dickens';
Word = scan(title,3,' ,');
run;
Which one of the following is the value of the variable WORD in the output data set?
A. T
B. of
C. Dickens
D. ' ' (missing character value)
Click Comment link to get answer

44 comments:

  1. Correct Answer is B

    ReplyDelete
  2. Anonymous7:33 AM

    D is the right answer

    ReplyDelete
  3. Anonymous3:22 PM

    why don't run the toy code on ur SAS?
    it's B.

    ReplyDelete
  4. Anonymous6:49 AM

    I tried it in SAS 9. The right answer is 'D.'

    ReplyDelete
  5. if the third parameter to the scan function is space and a comma (' ,') then answer is B, If third paramter is only a comma (',') then answer is D.

    ReplyDelete
  6. Anonymous7:06 PM

    The funny thing is, my SAS 9.0 result shows the result is D

    ReplyDelete
  7. The answer is D since the delimiter here is specified as ','

    ReplyDelete
    Replies
    1. Its specified as ' ,' with a space in it!

      Delete
  8. Anonymous10:29 AM

    Sorry I'm the one in the floor two place above. And I made the typo mistake the correct is B, the result with SAS 9.0 is "of", you can try it also by paste the code into the sas too.

    ReplyDelete
  9. Sorry my bad. I did not see the space. The answer is B

    ReplyDelete
  10. Anonymous10:10 AM

    B. Checked in SAS v.9.

    ReplyDelete
  11. KayCommaDee2:49 PM

    correct me if i am wrong... ash far ash i know, this is incorrect ashwell.

    ReplyDelete
  12. Anonymous1:33 PM

    can some one please explain thanks

    ReplyDelete
  13. Anonymous1:12 PM

    To create the LastName variable to store the employee's last name, you write an assignment
    statement that contains the following SCAN function:
    LastName=scan(name,1,' ,');
    Note that a blank and a comma are specified as delimiters. You can also write the function
    without listing delimiters, because the blank and comma are default delimiters.
    LastName=scan(name,1);

    so answer is d

    ReplyDelete
  14. Anonymous5:13 AM

    In this example, the placement of the quotations around the delimiter, the comma, is critical – if there were NO space (‘,’), the value returned would be ‘ ‘ (missing character value). However, having the space before the delimiter (' ,') returns the 'of', so it is 'B' instead of 'D'.

    ReplyDelete
  15. Anonymous11:17 PM

    People run the code and check ! answer is B

    ReplyDelete
  16. Anonymous11:13 AM

    we can specify 2 delimiters in scan functions.so answer B.I executed it.

    ReplyDelete
  17. You cannot specify a multi-character delimiter in scan, so ' ,' is actually specifying 2 delimiters, a comma and a space.

    Additionally, in this example the only comma is right next to a space. SAS treats consecutive delimiters as 1, so if the scan statement asked for word #7, the output would be 'J.'

    ReplyDelete
  18. Anonymous6:18 PM

    Answer is B.
    Wanted to hear more logic.
    Scan Variable Title 3rd word ( of ), is that space and ',' makes to take the whole word "of"?

    A, C does not make any sense, D may be a wild guess. Close call and right answer is C.

    Reason ? So we can answer correctly in exam.

    ReplyDelete
    Replies
    1. Anonymous12:18 AM

      I don't understand. Why does it take the whole word of "of"?

      Delete
  19. Anonymous2:55 PM

    the freaking code has a space as a delimiter along with comma, thats why answer is B. I don't know how the hell they expect us to notice that without actually running the code during the exam!! if it was just a comma then it would be D. I tried both code in SAS.

    ReplyDelete
  20. What is the point of you guys pasting code in SAS to see the answer?

    Funny how everyone wants to just get the answer right...guys you will not have SAS in the exam room!!

    People should focus more on the logic why they think what the answer should be!! Come on people grow up!!

    ReplyDelete
  21. Here you guys think about these codes and what they will give you:

    data work.test;
    Title = 'A Tale of Two Cities, Charles $J. Di $ ckens';
    Word = scan(title,7,' ');
    run;

    data work.test1;
    Title = 'A Tale of Two Cities, Charles $J. Di $ ckens';
    Word = scan(title,7,' $');
    run;

    data work.test2;
    Title = 'A Tale of Two Cities, Charles $J. Di $ ckens';
    Word = scan(title,7,'$');
    run;

    ReplyDelete
  22. Anonymous1:22 AM

    this prog is quite complicated .....

    ReplyDelete
  23. This is a tricky question mostly because of the formatting in the blog. If the delimiter is ' ,' then the answer is B - (Of ).

    Here both the delimiters are valid ' ' and ',' which can be combined and written as:
    ' ,' or ', '. So the third word that is separated by a space ' ' or a comma ',' is 'Of'.

    This is what the question asks for.


    However, the space is not very visible. So if there is no space in question, then the answer is missing. As there are no two commas to separate the strings into three 'words'. And the question asks for the third 'word' separated by the delimiter.

    ReplyDelete
  24. bec space is default delimitre ans is b

    ReplyDelete
  25. answer is D. reason is because in the code....Word = scan(title,3,' ,');... there is a comma in ','. if there wasnt any commas then it would be B because SAS is going by the spaces. in our case, it is going by comma and there is only one comma so it runs out and answer is missing.

    ReplyDelete
  26. Anonymous8:45 PM

    Correct answer is B, Here is the result from code:
    submitted code.
    work.test;
    Title = 'A Tale of Two Cities, Charles J. Dickens'; Word = scan(title,3,' ,');
    run;
    proc print data=retail;
    run;
    Result:
    Obs: 1
    Title: A Tale of Two Cities, Charles J. Dickens
    Word: of


    ReplyDelete
  27. Correct answer is D.

    ReplyDelete
  28. Anonymous9:48 PM

    GO TO tITLE THIRD WORD IS OF
    B

    ReplyDelete
  29. Answer is B.

    Because SAS treats 2 delimiters as one.in this case we have space and comma ' ,'.Thus SAS will interpret only space and NOT comma and give us answer B.


    IF only comma, then answer D


    Hence for this question correct answer checked in SAS is B

    ReplyDelete
    Replies
    1. Anonymous7:13 PM

      From my experience, the logic behind this is not what you think. if you specify two delimiters, SAS will interpret either one as one delimiter, or both as one delimiter, not space only. To prove that, plz try to replace all space by comma. SAS will return 'of' as third word as well if you specify 'space + ,' as delimiter.

      Thx


      I am not sure SAS has changed the logic in newer version

      Delete
    2. Anonymous7:18 PM

      Forgot to mention, although the logical is subtle, but the answer is B anyway, if there is a space before ','

      Delete
  30. I have read your blog its very attractive and impressive
    SAS Training in Bangalore

    ReplyDelete