Hi Friend,
I am new to SAS and while solving the problem stuck in very basic step. I have three coloumn data is like Grade sub Grade and their average value. I have take average of Grade and Sub-grade. Thank you...
Data Example
InputData | Output | ||||||
Col 1 | Col 2 | Avg | Average of Avg | ||||
A | A1 | 15 | Col 1 | Col 2 | Total | ||
A | A2 | 13 | A | A1 | 15 | ||
A | A3 | 16 | A2 | 13 | |||
A | A4 | 11 | A3 | 16 | |||
B | B1 | 12 | A4 | 11 | |||
B | B2 | 11 | A Avg | 13.75 | |||
B | B3 | 13 | B | B1 | 12 | ||
C | C1 | 17 | B2 | 11 | |||
C | C2 | 18 | B3 | 13 | |||
C | C3 | 13 | B Avg | 12 | |||
C | C4 | 20 | C | C1 | 17 | ||
C | C5 | 20 | C2 | 18 | |||
C3 | 13 | ||||||
C4 | 20 | ||||||
C5 | 20 | ||||||
C Avg | 17.6 | ||||||
Grand Total | 14.91666667 |
That's actually better done in either proc report or tabulate.
Possibly proc PRINT as well.
One way:
data have;
informat Col1 Col2 $5. Avg best5.;
input Col1 Col2 Avg ;
label
Col1 = "Col 1"
Col2 = "Col 2"
;
datalines;
A A1 15
A A2 13
A A3 16
A A4 11
B B1 12
B B2 11
B B3 13
C C1 17
C C2 18
C C3 13
C C4 20
C C5 20
run;
proc tabulate data=have;
class col1 col2;
var avg;
table col1*(col2 All='Group Avg') All='Grand Total',
avg=''*mean='Total'*f=best7.;
run;
Adjust the format for the desired number of decimals.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.