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
C
ReplyDeleteD. . (missing numeric value)
ReplyDeleteC as there is no @ after the input the pointer will move to age 7-8 and the out put 40 for age
ReplyDeleteThe answer is C (40). Here is my program:
ReplyDeletedata 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;
Answer should be D(missing); question talks about when the conditon is "sue" and not the program output
ReplyDeleteAnyone can exaplain me which is the right answer and why? Please. Thanks
ReplyDeleteMac: Answer is C because after reading following statement
ReplyDeleteinput 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.
Ok
Deletecan you please explain more clearly or any other way? i am not getting this
DeleteI thougth answer is D but I am not sure anymore after running the above script given by Anonymous. It gives the output:
ReplyDeleteObs name age idnum
1 Ruth . 2
2 Sue 0 .
An thus I am even more puzzled. Any ideas?
becuase, the original data set of this Question is
DeleteRuth 39 .....!! that reads 7-8 column right way..
there is double-spaced blanks between Ruth and 39.
Its the 0 from 40 as, if employee_name='Sue' then input age 7-8 so, at 7 it is 0 not 40;
ReplyDeleteI have the same result running the code given above
ReplyDelete1 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?
Age is read only for sue, for all other observation idnum is read. So in output you will have 3 observations.
ReplyDeleteNo...First of all the spacing given in the data sets are inaccurate.
DeleteSecondly even if you correct them and run the program you only get 2 observations and 3 variables.
Please check and confirm.
The o/p have 3 variables and 2 observations
ReplyDeleteemployee_name, age and idnum for each observation..
the answer is D.
ReplyDeleteTo 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;
data employee;
ReplyDeleteinput 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 .
The correct answer should be '0'.
ReplyDeleteHere is the output:
Obs name age idnum
1 Ruth . 2
2 Sue 0 .
cheers
ferrat
When I debug the program:
ReplyDelete43 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)
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?
ReplyDeleteObs name age idnum
1 Ruth . 2
2 Sue 0 .
i think the answer is D.
ReplyDeletea
ReplyDeleteguys common, 0 is not in the option and 40 cant be the answer either for 2 reasons
ReplyDelete1. 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
in this program you will never get the cond if employee_name = 'Sue' as true because sas reads it
ReplyDeletefor 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.
i think the answer is D, becoz when "Sue" is read the data stored in PVD will be "Sue " as name
ReplyDelete$ 1-4.
So when the employee name is Sue , name="Sue" is not true thus the if loop will not process
Sakar Sham;
ReplyDeleteAnswer sheet ; "B" = 33 ? no clue. Seems need more conceptual and logical base.
Folks , I put the data nicely to fit ( fixed column )
ReplyDeleteNO 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!
are we saying it's missing value becasuse the output will be "0_" (with a space)
ReplyDeleteand since, space is not a stanrard numeric value
it will result in Missing value?
. 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.
ReplyDelete. 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
Behind the schenes:
ReplyDelete1)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!
Excellent explanation. Thank you.
Deletei'd agree with this below
ReplyDeleteAnonymous9: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?
I' all so test it, and get answer D.
ReplyDeleteBelow is my test...
employee_
name age idnum
Ruth . .
d
ReplyDeleteAns is D.
ReplyDeleteGuys 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;
It is C, page 9 of the following doc explains in detail
ReplyDeletehttp://www2.sas.com/proceedings/sugi29/253-29.pdf
You can test using the following code. Run without the @ in the input line, then uncomment and run again.
Deletedata 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;
B
ReplyDeleteAnswer 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.
ReplyDeletedata test;
ReplyDeleteinfile 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).
Answer is D
ReplyDeleteC, the tricky thing to watch here is that name and age have to blanks in between them
ReplyDeleteI 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/
ReplyDeleteAnd now it's clear that the answer is C.
gm;;
ReplyDeletec
C
ReplyDeleteAnswer 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.
ReplyDeleteThis is the correct answer and for the right reasons.
DeleteJust run the program for yourself to check it.
Answer is really mean to be C (40)
ReplyDeleteThe 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!
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.
ReplyDeleteCAN SAS standardize it's language?
Please try program in SAS before you post answers here.... B is right answer.
ReplyDeletegclub
gclub casino online
Your blog is very useful for me.I really like you post.Thanks for sharing.
ReplyDeleteทองดีฟันขาว
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)
ReplyDeleteporn
ReplyDelete