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
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.
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)
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;
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
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;
Yes, But i am not able to debug... Kindly help
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?
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.
Thanks a ton. The solution worked.. @PaigeMiller
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.