How to find the mean value of a column

Reply
Occasional Contributor
Posts: 7

How to find the mean value of a column

[ Edited ]

Everything in my code works just fine. I am struggling with how to set up a code to find the mean of a column and be where I want it alongside of the separate sums of the units and total sales. Also, how do I create a title for the final row to indicate what that line means, i.e. "Total/Average"? I've attached the png picture of my result.

 

data bikes1;
infile "/folders/myfolders/austin.txt" dlm='09'x;
length
Country $14
Bike $13
Model $10
Units 4
Price 6
TotalSales 7
;
informat Price dollar6. TotalSales dollar7.;
format Price dollar6. TotalSales dollar7.;
input Country Bike Model Units Price TotalSales;
run;

proc print data=bikes1 noobs;
format Units comma7. TotalSales dollar7.;
sum Units TotalSales;
run;

*
USA Road Bike Trek 5000 $2,200 $11,000
USA Hybrid Trek 4500 $650 $2,925
USA Road Bike Cannondale 2000 $2,100 $4,200
USA Mountain Bike Trek 6000 $1,200 $7,200
USA Mountain Bike Cannondale 4000 $2,700 $10,800
United Kingdom Hybrid Cannondale 500 $880 $440
United Kingdom Hybrid Trek 800 $490 $392
United Kingdom Road Bike Cannondale 1200 $2,123 $2,548
United Kingdom Road Bike Trek 2444 $2,100 $5,132
United Kingdom Mountain Bike Trek 1211 $1,121 $1,358
Italy Mountain Bike Trek 3400 $1,877 $6,382
Italy Road Bike Trek 4500 $2,890 $13,005
Italy Hybrid Trek 700 $690 $483
France Road Bike Cannondale 900 $3,700 $3,330
France Road Bike Trek 3400 $2,500 $8,500
France Hybrid Trek 1100 $540 $594
France Mountain Bike Cannondale 800 $1,899 $1,519
France Mountain Bike Trek 5600 $1,300 $7,280
;

Attachment
Grand Advisor
Posts: 17,332

Re: How to find the mean value of a column

Look at Proc print and the SUM statement. 

Or Proc tabulate.  

Respected Advisor
Posts: 4,606

Re: How to find the mean value of a column

Something like

 

data bikes1;
length
Country $14
Bike $13
Model $10
Units 4
Price 6
TotalSales 7
;
informat Price dollar6. TotalSales dollar7.;
format Price dollar6. TotalSales dollar7.;
input Country & Bike & Model Units Price TotalSales;
datalines;
USA  Road Bike  Trek 5000 $2,200 $11,000
USA  Hybrid  Trek 4500 $650 $2,925
USA  Road Bike  Cannondale 2000 $2,100 $4,200
USA  Mountain Bike  Trek 6000 $1,200 $7,200
USA  Mountain Bike  Cannondale 4000 $2,700 $10,800
United Kingdom  Hybrid  Cannondale 500 $880 $440
United Kingdom  Hybrid  Trek 800 $490 $392
United Kingdom  Road Bike  Cannondale 1200 $2,123 $2,548
United Kingdom  Road Bike  Trek 2444 $2,100 $5,132
United Kingdom  Mountain Bike  Trek 1211 $1,121 $1,358
Italy  Mountain Bike  Trek 3400 $1,877 $6,382
Italy  Road Bike  Trek 4500 $2,890 $13,005
Italy  Hybrid  Trek 700 $690 $483
France  Road Bike  Cannondale 900 $3,700 $3,330
France  Road Bike  Trek 3400 $2,500 $8,500
France  Hybrid  Trek 1100 $540 $594
France  Mountain Bike  Cannondale 800 $1,899 $1,519
France  Mountain Bike  Trek 5600 $1,300 $7,280
;

proc tabulate data=bikes1;
class Country Bike Model;
var units TotalSales price;
table Country*Bike*Model all="Total/Average", 
    units*sum=""*format=comma7. 
    price*mean=""*format=dollar6.
    totalsales*sum=""*format=dollar7.;
run;
PG
Ask a Question
Discussion stats
  • 2 replies
  • 234 views
  • 0 likes
  • 3 in conversation