Pyrite | Level 9

PROC MEANS with a BY group

data strength;
input id program\$ s1 s2 s3 s4 s5 s6 s7;
datalines;
1 co 81 84 83 83 85 85 85
2 co 77 78 79 79 81 82 81
3 co 84 85 87 89 88 85 86
4 co 74 75 78 78 79 78 78
5 co 76 77 77 77 77 76 76
6 co 84 84 86 85 86 86 86
7 co 79 80 79 80 80 82 82
8 co 78 78 77 76 75 75 76
9 co 78 80 77 77 75 75 75
10 co 84 85 85 85 85 83 82
11 co 83 83 85 85 86 87 87
12 RI 79 82 82 83 84 84 82
13 RI 88 89 91 90 93 93 95
14 RI 83 83 84 83 84 86 86
15 RI 81 81 82 82 82 83 85
16 RI 87 88 90 89 89 91 93
17 RI 80 82 83 85 86 88 88
18 RI 82 83 84 84 83 85 87
19 RI 84 85 85 85 86 88 90
20 RI 80 80 82 83 83 84 85
21 RI 85 87 88 88 90 90 91
22 RI 87 88 88 87 87 86 86
;
run;
proc print data=strength;
run;
proc means data=strength mean std var;
var s1 s2 s3 s4 s5 s6 s7;
by program;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

Re: why it does not work

You have to sort your data appropriately first

``````proc sort data=strength;
by program;
run;

proc means data=strength mean std var;
by program;
var s1 s2 s3 s4 s5 s6 s7;
run;``````
6 REPLIES 6
Super User

Re: why it does not work

You have to sort your data appropriately first

``````proc sort data=strength;
by program;
run;

proc means data=strength mean std var;
by program;
var s1 s2 s3 s4 s5 s6 s7;
run;``````
Pyrite | Level 9

Thank you

Super User

Re: why it does not work

If it does not give you a clue right away, post it here, using the {i} button.

Pyrite | Level 9

thank you

Super User

Re: thank you

The output would look slightly different but you can use a CLASS statement instead of BY which will not generate the not sorted by BY variables error.

```proc means strength=have mean std var;
var s1 s2 s3 s4 s5 s6 s7;
class program;
run;```

If you have large data with lots of values for the class variables there can be performance issues.

Pyrite | Level 9

Re: thank you

thank you

Discussion stats
• 6 replies
• 608 views
• 1 like
• 4 in conversation