Obsidian | Level 7

## Calculation of variance of data in two tables

Could anyone help how to create a table having calcuation of variance of two columns  in two different tables.

Example : Suppose I have Table A and Table B

Column XYZ in A and ABC in B.

I have to create a table having new variable EFH which tells me the percentage DIFFERENCE of XYZ and ABC.

Thanks

3 REPLIES 3
SAS Super FREQ

## Re: Calculation of variance of data in two tables

I don't know what "percentage difference" means, but to get the variances you can either compute the two variances and then merge the results, or you can merge the data and then compute the two variances. Here is the second method;

``````%let ds1 = sashelp.class;
%let var1 = height;
%let ds2 = sashelp.cars;
%let var2 = mpg_city;

data want;
merge &ds1(keep=&var1) &ds2(keep=&var2);
run;

proc means data=want var;
output out=Vars var= / autoname;
run;

proc print; run;``````

If you now want the difference between these variances, write a DATA step:

``````data want;
set Vars;
/* not sure what formula you want to use here... */
format EFH PERCENTN7.2;
EFH = (&var1._Var - &var2._Var) / (&var2._Var);
run;``````
Super User

## Re: Calculation of variance of data in two tables

It sounds like you're not talking about the statistical definition of variance here but the accounting definition of variance. You should clarify your formula.

You can merge your tables and then calculate the difference, either PROC SQL or a data step will work.

Post sample data for sample code, please include data in the form of a data step so we can read it in directly to SAS.

Obsidian | Level 7

## Re: Calculation of variance of data in two tables

Yes, I was talking about mathematical variance of finding the percentage difference of the values. I got another ans to this. Thanks for your help

Discussion stats
• 3 replies
• 1843 views
• 0 likes
• 3 in conversation