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';
input sqfeet bedrooms baths street $ price : dollar10.;
run;
How many observations will the output data set contain?
A. 0
B. 3
C. 5
D. 7
Click Comment link to get answer
Its B
ReplyDeleteB
ReplyDeleteif style = 'CONDO' or style = 'RANCH';
ReplyDeleteThe Ans is: B. 3
RANCH,1250,.....
CONDO,1400,.....
RANCH,1500,.....
The answer is D. Since you define variable style in the input statement before the if statement, you will have 7 variables.
ReplyDeleteB
ReplyDeleteit's asking about the output datset
Hi Anonymous,
ReplyDeleteThe answer is B, because once you tell sas some condition as we have here if style = 'CONDO' or style = 'RANCH'; then it want do anything else.
what do u mean by this?
DeleteYes the answer is B
ReplyDeleteI ran the code.
Agreed. The answer is not "D", it's B. 'If' is defined after defining the style variable, but it is defined before all the other variables (ie., sqfeet, bedrooms baths street etc.).
ReplyDeleteif the statment has 'then' before input, eg.if...then input...; the answer is d
ReplyDeletecould someone provide the code; thank you
ReplyDeletere: code above, thanks, have it just posting it here (need to study major difference b/w this one and #107)
ReplyDeletedata work.condo_ranch;
infile datalines dsd;
input style $ @;
if style = 'CONDO' or style = 'RANCH';
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;
its b
ReplyDeleteya ans is B
ReplyDeletemy mail
lotlikar.aniket44@gmail.com
ans is D
ReplyDeletecan you plz elaborate y answer is D...
DeleteIt is B. That is a "Subsetting IF" statement. Notice that there is no "THEN" part to it. Since "OUTPUT" is implied before "RUN", only observations that make it past the subsetting IF will be output.
ReplyDeletetq
DeleteThank u...
DeleteANSWER IS D
ReplyDeleteThe answer is D. 7 observations will be made because the style variable is defined before the IF statement. However, only 3 of those observations will be complete with all variables.
ReplyDeleteThe output will be
DeleteRANCH,1250,2,1,Sheppard Avenue,"$64,000"
SPLIT
CONDO,1400,2,1.5,Market Street,"80,050"
TWOSTORY
RANCH,1500,3,3,Kemble Avenue,"$86,650"
SPLIT
SPLIT
This is an example of a subsetting if statement as part of a data step and has its own special syntax and meaning.
DeleteAny observation failing the if condition will not be output.
Thus, B and only 3 observations
The subsetting IF statement (ie IF statement without 'then') causes the DATA step to continue processing only those raw data records or those observations from a SAS data set that meet the condition of the expression that is specified in the IF statement. That is, if the expression is true for the observation or record (its value is neither 0 nor missing), SAS continues to execute statements in the DATA step and includes the current observation in the data set.
ReplyDeleteIf the expression is false (its value is 0 or missing), no further statements are processed for that observation or record, the current observation is not written to the data set, and the remaining program statements in the DATA step are not executed. SAS immediately returns to the beginning of the DATA step because the subsetting IF statement does not require additional statements to stop processing observations.
Excellent explanation!
DeleteYou da real MVP
Delete
DeleteAwesome explanation
D
ReplyDeleteB
ReplyDeleteAnswer is D guys. There is no output or delete statement. So when the if condition does not satisfies the observation will have only style and the other variables will be set to missing.
ReplyDeletedata work.condo_ranch;
ReplyDeleteinfile datalines dsd;
input style $ @;
if style = 'CONDO' or style = 'RANCH';
input sqfeet bedrooms baths street $ price : dollar10.;
cards;
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"
;
proc print data=condo_ranch;
run;
B
ReplyDelete