Solved
Contributor
Posts: 22

# Computing coefficient of variation in two dimenstional groups

[ Edited ]

Hello.

I am having a trouble in computing cv in two dimensional groups.

My dataset looks like this.

 class1 class2 id var1 var2 1 x a 4 5 1 y a 4 5 2 x b 3 6 2 x c . 3 3 x a 4 5 3 x b 3 6 3 y c . 3

I want to calculate cv of var1 and var2 for each class1-class2 groups such as 1-x, 1-y, 2-x, 3-x, 3-y.

I also want to skip missing variables in computing cv.

I tried

proc sql;

create table want as

select *, std(var1) as std_var1, mean(var1) as mean_var1, calculated std_var1/calculated mean_var1 as cv_var1

from have

group by class1, class2;

quit;

but I couldn't get the data that I want.

If you have any idea, plz share it with me.

Accepted Solutions
Solution
‎03-18-2018 09:24 AM
Posts: 3,278

## Re: Computing coefficient of variation in two dimenstional groups

Show us what you get. Show us what you want.

--
Paige Miller

All Replies
Posts: 3,278

## Re: Computing coefficient of variation in two dimenstional groups

[ Edited ]

@Sejin wrote:

Hello.

I am having a trouble in computing cv in two dimensional groups.

My dataset looks like this.

 class1 class2 id var1 var2 1 x a 4 5 1 y a 4 5 2 x b 3 6 2 x c . 3 3 x a 4 5 3 x b 3 6 3 y c . 3

I want to calculate cv of var1 and var2 for each class1-class2 groups such as 1-x, 1-y, 2-x, 3-x, 3-y.

I also want to skip missing variables in computing cv.

I tried

proc sql;

create table want as

select *, std(var1) as std_var1, mean(var1) as mean_var1, calculated std_var1/calculated mean_var1 as cv_var1

from have

group by class1, class2;

quit;

but I couldn't get the data that I want.

Be specific. What do you get (show us), and what do you want (show us).

--
Paige Miller
Contributor
Posts: 22

## Re: Computing coefficient of variation in two dimenstional groups

When I ran my code, I got mean values by groups just as I wanted, but I could not pass missing values in calculation.

Also, in calculating standard deviation values, it neither calculated the value group by group nor passed missing values.

Solution
‎03-18-2018 09:24 AM
Posts: 3,278

## Re: Computing coefficient of variation in two dimenstional groups

Show us what you get. Show us what you want.

--
Paige Miller
Contributor
Posts: 22

## Re: Computing coefficient of variation in two dimenstional groups

Well.. it suddenly worked

Super User
Posts: 10,850

## Re: Computing coefficient of variation in two dimenstional groups

Why not use

proc means data=have cv ;

by class1 class2;

var var1 var2;

run;

☑ This topic is solved.

Discussion stats
• 5 replies
• 156 views
• 0 likes
• 3 in conversation