BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
AnkitaSingh_901
Calcite | Level 5

This project will use the data set sashelp.shoes. Write a SAS program that will: • Read sashelp.shoes as input. • Create a new SAS data set, work.shoerange. • Create a new character variable SalesRange that will be used to categorize the observations into three groups. • Set the value of SalesRange to the following: o Lower when Sales are less than $100,000. o Middle when Sales are between $100,000 and $200,000, inclusively. o Upper when Sales are above $200,000. Run the program, then use additional SAS procedures to answer the following questions: Question 3: How many observations are classified into the “Lower” group? Question 4: What is the mean value of the Sales variable for observations in the “Middle” group? Round your answer to the nearest whole number.

 

I am not able to get the mean in the second question

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Also, I point out that your SQL will produce the wrong answer in the presence of missing values, better to use PROC MEANS to compute N as I showed.

--
Paige Miller

View solution in original post

7 REPLIES 7
Quentin
Super User

Have you created work.shoerange successfully?

 

Please show your code for creating that dataset, your code for answering the first question, and the code you have tried for answering the second question.  That will help people help you.

 

The good news is your class is using sashelp.shoes as input, so if you post your code, everyone will be able to run it.

 

Also, please describe whether your are struggling with error messages (pleas include them) or incorrect results (please describe how they are incorrect)

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
AnkitaSingh_901
Calcite | Level 5

This is my entire code

 

data shoerange;
set sashelp.shoes;
length salesrange $8;
if sales lt 100000 then salesrange = "lower";
if 100000 gt sales lt 200000 then salesrange = "middle";
if sales gt 200000 then salesrange = "upper";
run;

proc sql;
select count(*)
from work.shoerange
where salesrange = "lower";
quit;

proc means data= shoerange mean;
by sales;
where salesrange = "middle";
run;

 

PaigeMiller
Diamond | Level 26

The first step in debugging this is a step that you should be doing. That is, look at the data in data set SHOERANGE and see if it has been created properly.

 

Here is the data in data set SHOERANGE

PaigeMiller_0-1670262813926.png

 

Is this correct? Should row 1 have salesrange = 'middle'? If not, then look at your code and figure out what you did wrong that wound up giving row 1 a sales range of 'middle' instead of 'lower'.

 

Also, once you fix that, I suggest that instead of using SQL and then PROC MEANS, you just use PROC MEANS, which is less typing than using both SQL and PROC MEANS.

 

proc means data=shoerange n mean;
class salesrange;
var sales;
run;

 

--
Paige Miller
AnkitaSingh_901
Calcite | Level 5

Yes, But i am not able to debug... Kindly help

 

PaigeMiller
Diamond | Level 26
if 100000 gt sales lt 200000 then salesrange = "middle";

The first part 100000 gt sales is the same as sales<100000, that doesn't seem to be what you want. What should it say to have values between 100000 and 200000 in the "middle" category?

--
Paige Miller
PaigeMiller
Diamond | Level 26

Also, I point out that your SQL will produce the wrong answer in the presence of missing values, better to use PROC MEANS to compute N as I showed.

--
Paige Miller
AnkitaSingh_901
Calcite | Level 5

Thanks a ton. The solution worked.. @PaigeMiller 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1436 views
  • 0 likes
  • 3 in conversation