turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Calculation of variance of data in two tables

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-17-2016 03:12 PM - edited 06-17-2016 03:13 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-17-2016 03:26 PM - edited 06-17-2016 03:35 PM

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;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-17-2016 03:27 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-23-2016 01:46 PM

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