BookmarkSubscribeRSS Feed
Pundalik_Rathod
Calcite | Level 5

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 1Col 2Avg  Average of Avg 
AA115  Col 1Col 2Total
AA213  AA115
AA316   A213
AA411   A316
BB112   A411
BB211  A Avg 13.75
BB313  BB112
CC117   B211
CC218   B313
CC313  B Avg 12
CC420  CC117
CC520   C218
      C313
      C420
      C520
     C Avg 17.6
     Grand Total 14.91666667
3 REPLIES 3
Reeza
Super User

That's actually better done in either proc report or tabulate. 

Possibly proc PRINT as well.

Cynthia_sas
SAS Super FREQ
PROC PRINT will only do the SUM at the subtotal and grand total rows on the report. So, Reeza's first instinct was correct to use either REPORT or TABULATE.

cynthia
ballardw
Super User

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 3 replies
  • 676 views
  • 0 likes
  • 4 in conversation