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
B
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteShould this be B? as I think it should be "D" . Please post your comment
ReplyDeleteIts B
ReplyDeleteAnswer should be D. Check out.
ReplyDeleteyeap i agree answer is D
ReplyDeleteD
ReplyDeleteanswer is b
ReplyDeleteD
Deletefk off you idiot
DeleteAnswer is 22.
ReplyDeleteThis is a free listing format and the cursor moves to the second record and picks up 22.
The answer is B
True. The column numbering is incorrect.
DeleteBut B is correct answer.
Answer is D
ReplyDeleteAnswer is B
ReplyDeleteif 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.
ReplyDeleteb is the best among the choices given.
yes,agree with Yogesh
DeleteAbsolutely this one would be '2'. They should modify the question.
DeleteThis comment has been removed by the author.
ReplyDeleteSeems like answer is D after all. Here is my log:
ReplyDeleteInvalid 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.
ANSWER IS D, I CHECKED
ReplyDeleteThe answer is B......
ReplyDeleteAs 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)
The correct ans in this case is C.
ReplyDeleteif a trailing '@'is used in input statement {which was supposed to be}then it would give the value 39.
C - correct ans
any doubt ?
answer is B
ReplyDeleterun 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;
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.
ReplyDeleteAnswer is D.
ReplyDeletedata 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 . .
The Answer is D.
ReplyDeleteWhy? 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;
nice1
DeleteExactly.
DeleteJust 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.
Think this question would make more sense if the raw data file was like this:
ReplyDelete---------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).
Sorry i'll post that again:
ReplyDelete---------10--------20--------30
Ruth~~39~11
Jose~~32~22
Sue~~~30~33
John~~40~44
The answer is D.
ReplyDeleteAfter 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 . .
ss
ReplyDeleteDefinitely B.Run the following:
ReplyDeletedata 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;
neither A-D
ReplyDeleteCan you explain WHY does this dataset have only 2 observations? Thanks
ReplyDeletedata 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
guys common, 2 is not in the option and 22 cant be the answer either for 2 reasons
ReplyDelete1. 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.
Sakar;
ReplyDeleteI 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
Nope, the answer is "C".
DeleteThe SAS System
Obs NAME AGE ID
1 RUTH . 22
2 SUE 40 .
answer is D for sure I agree with Proudy...
ReplyDeletecan somebody please explain why the pointer would move down the row to check the condition?
ReplyDeleteI'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
you need the single trailing @ so it could remain in the same row :)
DeleteI have give this problem to an university teacher and will post it as I get the reason behind.
ReplyDeleteWe 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.
ReplyDeleteHope this helps.
Thank you, this is the only explanation that made sense.
Deletei agree!
Deletewats the final answer??
ReplyDeleteB
ReplyDeleteC is correct, align the raw data as per ruler,
ReplyDelete--------10-------20-------30
Ruth 39 11
Jose 32 22
Sue 30 33
John 40 44
it's c god you guys are dumb
ReplyDeletedata test;
ReplyDeleteinfile 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).
You can't really see it but the datalines are:
DeleteRuth<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.
gm;;;;
ReplyDeleteD
B
ReplyDeletePlease try program in SAS before you post answers here.... B is right answer
ReplyDeleteThis comment has been removed by the author.
ReplyDeletedata test;
ReplyDeleteinput 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';
To Nayan,
DeleteI'm getting the same answer when I run the code and just reading from columns 10-11 of the second input line.
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).
ReplyDeleteTo 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.
The only useful explanation. Thanks so much!
DeleteAnswer B
ReplyDeleteTHANKS!!! A GOOD EXPERIENCE.
ReplyDeletegclub
gclub casino online
Very nice post.really I apperciate your blog.Thanks for sharing.keep sharing more blogs.
ReplyDeleteทองดีฟันขาว