Desktop productivity for business analysts and programmers

Sort Mean in Ascending order without Proc Sort

Reply
Occasional Contributor
Posts: 7

Sort Mean in Ascending order without Proc Sort

Hi,
If I have a list of saleprice, but I need to get the mean of it (in ascending order) and categories under One variable FloorAreaCat. How do I write the code in Single Proc means step? (p/s I do not want to use Proc sort step in this case)
Appreciate if can help.

 

Thanks!

Super User
Posts: 20,236

Re: Sort Mean in Ascending order without Proc Sort

Posted in reply to BabyWS2001
AFAIK this isn't possible, without an additional step. If you're working with a single variable consider using PROC SQL instead.
Occasional Contributor
Posts: 7

Re: Sort Mean in Ascending order without Proc Sort

What if under the FloorAreaCat consist of "None", "Equal" or "Type" variables, can we do it?

Super User
Posts: 20,236

Re: Sort Mean in Ascending order without Proc Sort

Posted in reply to BabyWS2001
AFAIK there's no way to sort based on the value of the MEAN. I'm not sure what the values of FloorAreaCat have to do with that.
Super User
Posts: 20,236

Re: Sort Mean in Ascending order without Proc Sort

proc sql;
create table want as
select make, mean(msrp) as avg_msrp format=8.1
from sashelp.cars
group by make /*BY or CLASS variables go here and in the SELECT statement*/
order by calculated avg_msrp ;
quit;
Super Contributor
Posts: 299

Re: Sort Mean in Ascending order without Proc Sort

Posted in reply to BabyWS2001
Do you want like:
TYPE 30.52
NONE 25.20
EQUAL 10.45
Occasional Contributor
Posts: 7

Re: Sort Mean in Ascending order without Proc Sort

[ Edited ]

How about the below? Can I sort the Mean in ascending order? I have already found the Mean value of my saleprice, and group it under the FlorrAreaCat but I can't seem to sort the Mean value. Can it be done under the same Proc Means Step?

 

FloorAreaCat   N Obs    Mean (SalePrice)

Equal                200       200000

None                800       150000

Small                 90        340000

Super User
Posts: 20,236

Re: Sort Mean in Ascending order without Proc Sort

[ Edited ]
Posted in reply to BabyWS2001

BabyWS2001 wrote:

How about the below? Can I sort the Mean in ascending order? I have already found the Mean value of my saleprice, and group it under the FlorrAreaCat but I can't seem to sort the Mean value. Can it be done under the same Proc Means Step?

 

FloorAreaCat   N Obs    Mean (SalePrice)

Equal                200       200000

None                800       150000

Small                 90        34000


That's DESCENDING order......

Trusted Advisor
Posts: 1,984

Re: Sort Mean in Ascending order without Proc Sort

Any problem that says you can't use PROC SORT to get things properly sorted seems like it's a made up problem.

--
Paige Miller
Super Contributor
Posts: 299

Re: Sort Mean in Ascending order without Proc Sort

Posted in reply to BabyWS2001

For your special requirements, entire thing can be done in a data step. No need for Proc Sort, Proc Means.

Do you like a data step?

Super User
Posts: 11,578

Re: Sort Mean in Ascending order without Proc Sort

Posted in reply to BabyWS2001

Provide a small example data set and what the result needs to look like.

Write a data step to provide the example data or Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

Any artificial restriction of "cannot use Proc sort" is similar to "I want to eat canned food without opening the can".

Occasional Contributor
Posts: 7

Re: Sort Mean in Ascending order without Proc Sort

[ Edited ]
Posted in reply to BabyWS2001

Is ok, cause this is my Uni SAS programing assignment question. Will try to find a way out if there no way to solve this question.

 

Thanks.

Super User
Posts: 20,236

Re: Sort Mean in Ascending order without Proc Sort

Posted in reply to BabyWS2001
Post the exact question then, there's the possibility you're misinterpreting the question.
Occasional Contributor
Posts: 7

Re: Sort Mean in Ascending order without Proc Sort

Here the  question

(q) list down in ascending order the mean sale price, categories under variable of FloorAreaCat. Use single Proc Means step to answer this question.

 

Super User
Posts: 20,236

Re: Sort Mean in Ascending order without Proc Sort

[ Edited ]
Posted in reply to BabyWS2001

A single PROC MEANS doesn't mean you can't use SORT in my opinion. Or maybe there is a way...I would check your class notes.

 


BabyWS2001 wrote:

Here the  question

(q) list down in ascending order the mean sale price, categories under variable of FloorAreaCat. Use single Proc Means step to answer this question.

 


 

Ask a Question
Discussion stats
  • 17 replies
  • 170 views
  • 0 likes
  • 5 in conversation