logo_learn_stats

Tips on how to Calculate a Weighted Reasonable in SAS (With Examples)

Posted on
banner 336x280

You’ll be able to virtue please see forms to calculate a weighted reasonable in SAS:

Mode 1: Calculate Weighted Reasonable

banner 468x60
proc sql;
    manufacture desk new_data as
    make a choice sum(weight * worth) / sum(weight) as weighted_average
    from original_data;
leave;

Mode 2: Calculate Weighted Reasonable via Team

proc sql;
    manufacture desk new_data as
    make a choice grouping_variable,
    sum(weight * worth) / sum(weight) as weighted_average
    from original_data
    team via grouping_variable;
leave;

Please see examples display virtue every mode with please see dataset in SAS:

/*manufacture dataset*/
knowledge original_data;
    enter sales_rep $ value quantity;
    datalines;
A 8 1
A 5 3
A 6 2
B 7 2
B 12 5
B 14 4
;
run;

/*view dataset*/
proc print knowledge=original_data;

Instance 1: Calculate Weighted Reasonable

Please see code displays calculate a weighted reasonable for the value variable, the use of the quantity variable as the burden:

/*calculate weighted reasonable of value*/
proc sql;
    manufacture desk new_data as
    make a choice sum(quantity * value) / sum(quantity) as weighted_average
    from original_data;
leave;

/*view weighted reasonable of value*/
proc print knowledge=new_data;

The weighted reasonable of value seems to be 9.70588.

Instance 2: Calculate Weighted Reasonable via Team

Please see code displays calculate the weighted reasonable of the value variable, grouped via the sales_rep variable:

/*calculate weighted reasonable of value, grouped via sales_rep*/
proc sql;
    manufacture desk new_data as
    make a choice sales_rep,
    sum(quantity * value) / sum(quantity) as weighted_average
    from original_data
    team via sales_rep;
leave;

/*view effects*/
proc print knowledge=new_data;

From the output we will see:

  • The weighted reasonable of value for gross sales rep A is 5.8333.
  • The weighted reasonable of value for gross sales rep B is 11.8182.

Alternative Assets

Please see tutorials give an explanation for carry out alternative ordinary duties in SAS:

Tips on how to Calculate the Heartless via Team in SAS
Tips on how to Calculate Correlation in SAS
Tips on how to Form Frequency Tables in SAS

banner 336x280

Leave a Reply

Your email address will not be published. Required fields are marked *