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)

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
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 

SAS Innovate 2025: Register Now

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!

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
  • 1804 views
  • 0 likes
  • 3 in conversation