ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 107

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

31 comments:

  1. Anonymous9:35 AM

    then:

    D. 7

    RANCH......
    SPLIT......
    CONDO......
    TWOSTORY...
    RANCH......
    SPLIT......
    SPLIT......

    ReplyDelete
  2. can I have the explaination?
    Thank you

    ReplyDelete
  3. Its d) 7. If is not subsetting the dataset but providing a condition. if style =' ' | ' ' THEN input.

    ReplyDelete
  4. Could you Please explain in detail..
    Since, If and then say.. do when condition satisfied in this case condition will satisfy for 3

    ReplyDelete
  5. Anonymous5:52 PM

    Can Anybody explaine properly. this seems like a miracle

    ReplyDelete
  6. Anonymous1:21 PM

    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

    Output looks similar to this fashion. Since we have input style $ @; then comes if then.

    ReplyDelete
  7. Anonymous1:30 PM

    The above explanation in wrong. Will have only 3 observations

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

    ReplyDelete
    Replies
    1. Anonymous11:27 AM

      Even though other styles except CONDO,RANCH has missing value those were considered as an observation as the styles were present.

      Delete
  8. Answer is D.
    Reason 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;

    ReplyDelete
    Replies
    1. Anonymous9:37 PM

      Thanks...Now that is the way to explain. Hate the other ppls who don't mention any fruitful comments, but throw something which confuses.

      Delete
    2. thanks.. 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?

      Delete
  9. Anonymous6:47 PM

    D for sure

    ReplyDelete
  10. Anonymous12:58 PM

    question though: #106 had also "input style $ @;" - the only difference I may note b/w these 2 is the THEN in the comparison line...

    ReplyDelete
  11. if we remove 'then' from the statement
    if style = 'CONDO' or style = 'RANCH' then

    only then the number of observations is 3, otherwise its 7

    ReplyDelete
    Replies
    1. Parineeti11:38 AM

      Thankyou! this helped a lot.

      Delete
  12. Anonymous4:38 PM

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

    ReplyDelete
  13. Anonymous12:26 PM

    Why we are getting the outcome with 7 observations?
    As 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

    ReplyDelete
  14. Anonymous11:07 AM

    We need to read the question carefully.

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

    ReplyDelete
  15. Anonymous11:17 AM

    Someone is right about the trailing @ which will hold the " Style"
    But only tree of them has all the information it has in the statements.

    ReplyDelete
  16. D because only the input is affected by the IF statement; not the output.

    ReplyDelete
  17. Anonymous6:39 PM

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

    ReplyDelete
  18. please anyone can give a better explanation to this its confusing me a lot

    ReplyDelete
  19. please anyone can give a better explanation to this its confusing me a lot

    ReplyDelete
  20. can u explain simple way to @ @@

    ReplyDelete
  21. if style = 'CONDO' or style = 'RANCH' then; : this statement gives 7 output

    and

    if style = 'CONDO' or style = 'RANCH';
    gives 3 output. please explain the logic behind

    ReplyDelete
  22. Anonymous6:41 AM

    the others there are with 'missing'

    ReplyDelete
  23. This comment has been removed by the author.

    ReplyDelete
  24. Anonymous1:21 PM

    if style = 'CONDO' or style = 'RANCH';
    if 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.

    ReplyDelete
  25. Anonymous9:19 PM

    Shouldn't the result come out like this?

    Ranch, 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

    ReplyDelete