ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 83

The SAS data set named COMPANY.PRICES is listed below:
COMPANY.PRICES
prodid price producttype sales returns
K12S 5.10 NETWORK 15 2
B132S 2.34 HARDWARE 300 10
R18KY2 1.29 SOFTWARE 25 5
3KL8BY 6.37 HARDWARE 125 15
DY65DW 5.60 HARDWARE 45 5
DGTY23 4.55 HARDWARE 67 2
The following SAS program is submitted:
libname company 'SAS-data-library';
data hware inter soft;
set company.prices (keep = producttype price);
if price le 5.00;
if producttype = 'HARDWARE' then output HWARE;
else if producttype = 'NETWORK' then output INTER;
else if producttype = 'SOFTWARE' then output SOFT;
run;
How many observations does the HWARE data set contain?
A. 0
B. 2
C. 4
D. 6
Click Comment link to get answer

26 comments:

  1. Anonymous5:57 AM

    if price le 5.00;

    So the Ans is B

    Obs price producttype
    1 2.34 HARDWARE
    2 4.55 HARDWARE

    ReplyDelete
  2. Anonymous8:39 AM

    can some one please explain in detail why it is B.

    ReplyDelete
  3. Following three observation satisfy condition if price le 5.
    B132S 2.34 HARDWARE 300 10
    R18KY2 1.29 SOFTWARE 25 5
    DGTY23 4.55 HARDWARE 67 2
    Out of the above 3 observation only 2 observation have producttype = 'HARDWARE', so number of observation in HWARE is 2, hence answer is B.

    ReplyDelete
  4. Anonymous8:29 AM

    A -- the else, if statements must end with an else statement

    ReplyDelete
  5. Anonymous12:48 PM

    I have seen many stupid comments in this blog but the one right above beats them all

    ReplyDelete
    Replies
    1. I have seen many hilarious posts in this blog but yours one beats them all :) :D

      Delete
  6. Anonymous4:30 PM

    True. The dudes high on something.

    ReplyDelete
  7. If we do not close loop for iF statement than it will not give any result.

    ReplyDelete
  8. Anonymous12:05 PM

    Is it open?

    ReplyDelete
  9. Anonymous1:40 PM

    ....

    ReplyDelete
  10. Anonymous5:31 AM

    data test;
    input prodid $ price producttype $ sales returns;
    cards;
    K12S 5.10 NETWORK 15 2
    B132S 2.34 HARDWARE 300 10
    R18KY2 1.29 SOFTWARE 25 5
    3KL8BY 6.37 HARDWARE 125 15
    DY65DW 5.60 HARDWARE 45 5
    DGTY23 4.55 HARDWARE 67 2
    ;run;

    data hware inter soft;
    set test;
    if price le 5.00;
    if producttype = 'HARDWARE' then output HWARE;
    else if producttype = 'NETWORK' then output INTER;
    else if producttype = 'SOFTWARE' then output SOFT;
    run;

    proc print data=hware; run;

    try it and you'll see that the answer is B for sur! there isn't any problem of "closing the IF ELSE statment !!"

    ps: sorry for my english

    ReplyDelete
    Replies
    1. Anonymous10:17 AM

      if price le 5.00; is an if sub-setting statement in this case

      Delete
  11. priyanka12:56 AM

    ans is B.

    there is no need to close an IF\THEN statement.
    its compulsory to close a DO statement.
    the above program posted by anonymous is correct.

    ReplyDelete
  12. data ganesh.company_prices;
    input @1 prodid $ @8 price 4.2 @13 producttype $9. @23 sales 3. @27 returns 2.;
    format price 4.2;
    datalines;
    K12S 5.10 NETWORK 15 2
    B132S 2.34 HARDWARE 300 10
    R18KY2 1.29 SOFTWARE 25 5
    3KL8BY 6.37 HARDWARE 125 15
    DY65DW 5.60 HARDWARE 45 5
    DGTY23 4.55 HARDWARE 67 2
    ;
    run;

    data company_prices;
    set ganesh.company_prices;
    if price le 5.00;
    if producttype = 'HARDWARE' then output = 'HWARE';
    else if producttype = 'NETWORK' then output = 'INTER';
    else if producttype = 'SOFTWARE' then output = 'SOFT';
    run;

    This syntax will give you 2 observation for Hardware and one for software;
    so B seems to be the correct answer. The question is output = 'SOFT' or output SOFT which one is correct; with output SOFT is giving errors.

    ReplyDelete
  13. Anonymous8:58 PM

    If two IF statements change the position each other, then what happened? why do sas data set HWARE have 4obs?

    ReplyDelete
    Replies
    1. Hware output takes 4 observations from hardware productype prior to 'if price' statement has run

      Delete
  14. actually there should be 3 observations as price is le 5. price 5 also should be considered. but we donot have that option.

    ReplyDelete
  15. How does the presence of ELSE statements affect the results ? Do we ignore any condition in ELSE in this case?

    ReplyDelete
  16. Anonymous1:48 AM

    Informative and helpful Article. Really good work. Appreciate it. You might be looking for Sales Order Management in Bangalore

    ReplyDelete