BookmarkSubscribeRSS Feed
jundy19
Calcite | Level 5

I have a dataset with 4 variables where var 1 is categorical. I'm trying to do the mean for var2 and var3 based on a proc rank i applied on a 3rd variable(Thus, i the want the mean var2 for 0,1,2,3 as well as the mean for var3 for each of them as well. How can I do that???

I tried doing proc means but it's giving me the mean for each variable in general not for each value of the ranks.

my code looks like this:

 

data myd1;

input var1 var2 var3 var4;

datalines;

1 200 300 55%

2 400 750 20%

3 400 400 90%

4 800 320 98%

5 500 200 80%

6 600 400 71%

7 900 900 22%

8 1000 9580 77%

9 100 3000 42%

10 760 1750 53%

;

proc rank data=myd1 groups=4 out=want;
var var4;
ranks groups;
run;

---------------------------

Thank you

1 REPLY 1
Sajid01
Meteorite | Level 14

From what I have comprehend from the question, you need the mean of var2 and var3 for each of the ranks 0,1,2 and 3. With this as the basis, the code would be like this. You are grouping based on the numeric values of the percentage



data myd1;
input var1 var2 var3 var4;
datalines;
1 200 300 55
2 400 750 20
3 400 400 90
4 800 320 98
5 500 200 80
6 600 400 71
7 900 900 22
8 1000 9580 77
9 100 3000 42
10 760 1750 53
;
run;

proc rank data=myd1 groups=4 out=want ;
var var4;
ranks groups;
run;
proc means data=want Mean maxdec=2;
class groups;
var var2 var3;
run;

 

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!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 345 views
  • 0 likes
  • 2 in conversation