DATA Step, Macro, Functions and more

read SAS data sets

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

read SAS data sets

Given the SAS data set PRICES:
PRICES
Prodid priceproducttypesalesreturns
K1255.10NETWORK152
B132S 2.34HARDWARE30010
R18KY2 1.29SOFTWARE255
3KL8BY 6.37HARDWARE12515

DY65DW 5.60HARDWARE455

DGTY23 4.55HARDWARE672
The following SAS program is submitted:
data hware inter cheap;
set prices(keep = productype price);
if producttype = ‘HARDWARE’ then output hware; else if producttype = ‘NETWORK’
then output
inter; if price le 5.00;
run;

 

How many observations does the HWARE data set contain?

Ans is 4. 

 

I know there are 4 obs with Hardware, but will the "if price le 5.00" affects the answer? causing only those hardware with price le 5.00 get selected and change the answer to 2 observations. Please help, thanks!!!


Accepted Solutions
Solution
‎09-26-2017 11:04 PM
Trusted Advisor
Posts: 1,566

Re: read SAS data sets

You put the IF PRICE aafter the OUTPUT statement, therefor it will not affect the results and you get 4 obs.

 

If you change the code so that IF PRICE preceeds the OUTPUT statement it will affect it.

View solution in original post


All Replies
Solution
‎09-26-2017 11:04 PM
Trusted Advisor
Posts: 1,566

Re: read SAS data sets

You put the IF PRICE aafter the OUTPUT statement, therefor it will not affect the results and you get 4 obs.

 

If you change the code so that IF PRICE preceeds the OUTPUT statement it will affect it.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 111 views
  • 1 like
  • 2 in conversation