ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 106

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

32 comments:

  1. Anonymous1:16 PM

    Its B

    ReplyDelete
  2. Anonymous9:30 AM

    if style = 'CONDO' or style = 'RANCH';

    The Ans is: B. 3

    RANCH,1250,.....
    CONDO,1400,.....
    RANCH,1500,.....

    ReplyDelete
  3. Anonymous1:14 AM

    The answer is D. Since you define variable style in the input statement before the if statement, you will have 7 variables.

    ReplyDelete
  4. Anonymous11:15 AM

    B
    it's asking about the output datset

    ReplyDelete
  5. Anonymous5:38 PM

    Hi Anonymous,
    The 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.

    ReplyDelete
    Replies
    1. Anonymous1:47 AM

      what do u mean by this?

      Delete
  6. Anonymous1:29 PM

    Yes the answer is B

    I ran the code.

    ReplyDelete
  7. Bombomba12:35 AM

    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.).

    ReplyDelete
  8. Anonymous12:34 PM

    if the statment has 'then' before input, eg.if...then input...; the answer is d

    ReplyDelete
  9. Anonymous12:34 PM

    could someone provide the code; thank you

    ReplyDelete
  10. Anonymous12:50 PM

    re: code above, thanks, have it just posting it here (need to study major difference b/w this one and #107)

    data 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;

    ReplyDelete
  11. Anonymous11:48 PM

    its b

    ReplyDelete
  12. ya ans is B
    my mail
    lotlikar.aniket44@gmail.com

    ReplyDelete
  13. Replies
    1. kanika8:44 AM

      can you plz elaborate y answer is D...

      Delete
  14. Anonymous9:08 AM

    It 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.

    ReplyDelete
  15. Anonymous7:37 PM

    ANSWER IS D

    ReplyDelete
  16. The 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.

    ReplyDelete
    Replies
    1. The output will be
      RANCH,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

      Delete
    2. Anonymous11:21 PM

      This is an example of a subsetting if statement as part of a data step and has its own special syntax and meaning.

      Any observation failing the if condition will not be output.

      Thus, B and only 3 observations

      Delete
  17. Anonymous10:32 PM

    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.
    If 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.

    ReplyDelete
    Replies
    1. Anonymous10:56 AM

      Excellent explanation!

      Delete
    2. Anonymous5:05 AM

      You da real MVP

      Delete

    3. Awesome explanation

      Delete
  18. Answer 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.

    ReplyDelete
  19. Anonymous11:24 PM

    data work.condo_ranch;
    infile 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;

    ReplyDelete