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;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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