The following SAS program is submitted:
data work.test;
Author = 'Christie, Agatha';
First = substr(scan(author,2,' ,'),1,1);
run;
Which one of the following is the value of the variable FIRST in the output data set?
A. A
B. C
C. Agatha
D. ' ' (missing character value)
Click Comment link to get answer
A
ReplyDeleteAnswer is 'A'
ReplyDeleteIf there is a space in between two parts of the variable 'author' then answer is D. Else answer is A
ReplyDeleteD -
ReplyDeletescan(author,2,',') returns "[space]Agatha", therefore First="[space]"
Right
DeleteA
ReplyDeleteCorrect answer is A.
ReplyDeleteEven if there is a space b/w the comma and the Agatha, it does not matter because 'blank' or ;space' is also one of the several(blank . < ( + | & ! $ * ) ; ^ - / , % default delimiters.
The default delimiters don't matter. The delimiters are defined. So the question is whether blank is a delimiter. Here it is whether the questioner meant it to be or not. Hence A is the answer. Remove the blank from the list and D is the answer.
Deletedata work.test;
Author = 'Christie, Agatha';
First = substr(scan(author,2,' ,'),1,1);
run;
This has blank and comma as delimiters.
data work.test;
Author = 'Christie, Agatha';
First = substr(scan(author,2,','),1,1);
run;
This just commma.
Very hard thing to notice as you can see looking at the two. Hope nothing like that is on the base sas, too easy to make a mistake.
Its D I compiled the program.....If there is no space then it is considered as option A
ReplyDeleteI compiled the program too and I got A as the answer. Even if I entered several space before the A.
ReplyDeletedata work.test;
Author = 'Christie, Agatha';
First = substr(scan(author,2,' ,'),1,1);
run;
Answer is A.
ReplyDeleteIf we dont mention space as delimiter in the scan function ,then answer would be D.
scan function executed first,it will give result as agatha.now substr funtion looks for first position character ie,1-1 ,results A so answer is A.
ReplyDeletedefinitely A, its separated by comma. so if you scan author for 2nd word. your answer is Agatha. and once you substring the first word, you get A.
ReplyDeleteHave you seen this?
ReplyDeletedata work.test;
Author = ‘Agatha Christie’;
First = substr(scan(author,1,’ ,‘)1 ,1);
run;
Which one of the following is the length of the variable FIRST in the output data set?
A. 1
B. 6
C. 15
D. 200
Can you relate these two?
Sakar Sham
That question has unusual Answer and could not relate.
ReplyDeleteSakar Sham
Same answer as the previous questions. The length of the substring hasn't changed. Therefore, the answer is A.
ReplyDeleteOutput:
Obs Author First
1 Agatha, Christie A
A
ReplyDeleteHere's the question, when I ran the coding this, I got "A" as an answer, but when I put 'First = substr(scan(author,2,','),1,1);' - without space before ',' I got "D" I don't know why, would you guys explain the reason? Thx
ReplyDeletethe reason is that where you use a ' ,' (a space and a comma in quotes) to specify the delimiter, then SAS considers spaces and commas to be delimiters and disregards them both ... if you use only the comma to specify the delimiter then EVERYTHING after the comma to the next comma or end of string is considered to be a word by the scan function .. including spaces
DeleteThe SCAN function treats two or more contiguous delimiters, such as the parenthesis and slash below, as one delimiter. Also, leading delimiters have no effect.
ReplyDeleteA
ReplyDeleteA
ReplyDeleteA
ReplyDeleteTwo parts need to pay attention cuz they were unclearly mentioned in this question.
ReplyDeleteFirst, in scan() function, if there is a space in ' ,' (not ','), SAS cannot find this user defined delimiter in var Author. Thus, in Author, whether this is a space after ',' doesn't matter because there is no space before ',' to be matched anyway. So SAS will always find second word "Agatha" (both ',' and space after it will be treated as default delimiters). Subtring it, we will always get 'A'. But note that the length of Author and First are 16 with space (in Author) and 15 without (in Author).
However, if there is no space in ',' in scan() function, the second part matters, which is whether there is a space after 'Christie,' in Author. If there is a space, the scan() function will return 'space + Agatha' cuz SAS will treat ',' as delimiter only. Thus, we will get ' ' missing char value in First. In contrast, if there is no space after 'Christie,' , the scan() function will return 'Agatha' and we will get 'A' in First. Again, note that the length of Author and First are 16 with space (in Author) and 15 without (in Author).
Thx!
Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care
ReplyDeletehttp://chennaitraining.in/qliksense-training-in-chennai/
http://chennaitraining.in/pentaho-training-in-chennai/
http://chennaitraining.in/machine-learning-training-in-chennai/
http://chennaitraining.in/artificial-intelligence-training-in-chennai/
http://chennaitraining.in/msbi-training-in-chennai/
http://chennaitraining.in/citrix-training-in-chennai/
Thank you for this blog on MSBI Certification.
ReplyDelete