A raw data file is listed below:
RANCH,1250,2,1,Sheppard Avenue,"$64,000"
SPLIT,1190,1,1,Rand Street,"$65,850"
CONDO,1400,2,1.5,Market Street,"80,050"
TWOSTORY,1810,4,3,Garris Street,"$107,250"
RANCH,1500,3,3,Kemble Avenue,"$86,650"
SPLIT,1615,4,3,West Drive,"94,450"
SPLIT,1305,3,1.5,Graham Avenue,"$73,650"
The following SAS program is submitted using the raw data file as input:
data work.condo_ranch;
infile 'file-specification' dsd;
input style $ @;
if style = 'CONDO' or style = 'RANCH' then
input sqfeet bedrooms baths street $ price : dollar10.;
run;
How many observations does the WORK.CONDO_RANCH data set contain?
A. 0
B. 3
C. 5
D. 7
Click Comment link to get answer
'D'
ReplyDeletethen:
ReplyDeleteD. 7
RANCH......
SPLIT......
CONDO......
TWOSTORY...
RANCH......
SPLIT......
SPLIT......
can I have the explaination?
ReplyDeleteThank you
Its d) 7. If is not subsetting the dataset but providing a condition. if style =' ' | ' ' THEN input.
ReplyDeleteCould you Please explain in detail..
ReplyDeleteSince, If and then say.. do when condition satisfied in this case condition will satisfy for 3
Can Anybody explaine properly. this seems like a miracle
ReplyDeleteRANCH 1250 2 1 Sheppard Avenue $64,000
ReplyDeleteSPLIT
CONDO 1400 2 1.5 Market Street $80,050
TWOSTORY
RANCH 1500 3 3 Kemble Avenue $86,650
SPLIT
SPLIT
Output looks similar to this fashion. Since we have input style $ @; then comes if then.
The above explanation in wrong. Will have only 3 observations
ReplyDeleteRANCH 1250 2 1 Sheppard Avenue 64000
CONDO 1400 2 1.5 Market Street 80050
RANCH 1500 3 3 Kemble Avenue 86650
I ran the code to confirm.
Even though other styles except CONDO,RANCH has missing value those were considered as an observation as the styles were present.
DeleteAnswer is D.
ReplyDeleteReason being statement "input style $ @;" will hold input stream until next input statement. Program will read next input statement only if style is condo or ranch. But even when style is not condo or ranch when run statement is executed output will be written with just style variable having value and all others will be missing. Check it out using the program given below.
data work.condo_ranch;
infile datalines dsd;
input style $ @;
if style = 'CONDO' or style = 'RANCH' then
input sqfeet bedrooms baths street $ price : dollar10.;
datalines;
RANCH,1250,2,1,Sheppard Avenue,"$64,000"
SPLIT,1190,1,1,Rand Street,"$65,850"
CONDO,1400,2,1.5,Market Street,"80,050"
TWOSTORY,1810,4,3,Garris Street,"$107,250"
RANCH,1500,3,3,Kemble Avenue,"$86,650"
SPLIT,1615,4,3,West Drive,"94,450"
SPLIT,1305,3,1.5,Graham Avenue,"$73,650"
run;
proc print;
run;
Thanks...Now that is the way to explain. Hate the other ppls who don't mention any fruitful comments, but throw something which confuses.
Deletethanks.. but..I thought,,, Because of "input style $ @", the raw data of next to 1st 'SPLIT' would be 1190, so next style would be '1190'... is that wrong?
DeleteD for sure
ReplyDeletequestion though: #106 had also "input style $ @;" - the only difference I may note b/w these 2 is the THEN in the comparison line...
ReplyDeleteif we remove 'then' from the statement
ReplyDeleteif style = 'CONDO' or style = 'RANCH' then
only then the number of observations is 3, otherwise its 7
Thankyou! this helped a lot.
Deletethe then in #107 gives all observations because no condition has been placed to subset the data. the absence of then in #106 is allowing the if statement act as a subsetting function in this case restricting the output to only 3.
ReplyDeleteWhy we are getting the outcome with 7 observations?
ReplyDeleteAs someone explained on earlier that @ sign will not let it move further and ends there, and it will not execute this statement,
if style = 'CONDO' or style = 'RANCH' then
and we are getting all style in the output.
So the culprit is @ sign and which works as the stop sing and halts right there and we get the result with 7 obs.
It is my understanding.
sakar Sham
We need to read the question carefully.
ReplyDelete20 birds came to a tree if a hunter kills 3 birds in one shot how many bird are in the tree?
If we do plus and minus the answer will be 17, but rest fly away no birds are awaiting for the second shots.
Here it is not asking the observations of the output but the observations in the data set before execution.
I read that way and got answer 'D'.
Thanks for reading may nasty comment.
Someone is right about the trailing @ which will hold the " Style"
ReplyDeleteBut only tree of them has all the information it has in the statements.
D because only the input is affected by the IF statement; not the output.
ReplyDelete'then' makes all the difference. In this case, there are 2 input statements one before 'if' and one after 'if'. Second input statement reads only 3 obs. but first one reads all 7. Hence final output will contain 7 obs. in total with missing values for all the variables in the second input statement.
ReplyDeletethanks
ReplyDeleteplease anyone can give a better explanation to this its confusing me a lot
ReplyDeleteplease anyone can give a better explanation to this its confusing me a lot
ReplyDeletecan u explain simple way to @ @@
ReplyDeleteif style = 'CONDO' or style = 'RANCH' then; : this statement gives 7 output
ReplyDeleteand
if style = 'CONDO' or style = 'RANCH';
gives 3 output. please explain the logic behind
the others there are with 'missing'
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteif style = 'CONDO' or style = 'RANCH';
ReplyDeleteif there is no then in above statement , the if condition satisfies with style = 'CONDO' and style='RANCH' and produces 3 obs in output.
if style = 'CONDO' or style = 'RANCH' then
in this case, the condition is asking only in these two cases provide the extra details. but it will produce all the 7 records with style and in this 7 four records will have missing values.
Shouldn't the result come out like this?
ReplyDeleteRanch, 1190,1,1,Rand Street,"$65,850"
CONDO, 1810,4,3,Garris Street,"$107,250"
RANCH, 1615,4,3,West Drive,"94,450"
Get the first value from the first input style $@ and Since the second input came from input sqfeet bedrooms baths street $ price : dollar10.; shouldn't we get the second value sqfeet beds street $price?
for example
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"?
this answer is 40