DATA Step, Macro, Functions and more

Computing coefficient of variation in two dimenstional groups

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

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.

class1class2idvar1var2
1xa45
1ya45
2xb36
2xc.3
3xa45
3xb36
3yc.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.

Thanks for reading the thread.


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

Re: Computing coefficient of variation in two dimenstional groups

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

--
Paige Miller

View solution in original post


All Replies
Respected Advisor
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

Posted in reply to PaigeMiller

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
Respected Advisor
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

Posted in reply to PaigeMiller

Well.. it suddenly worked

srry for waisting your time

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.

Need further help from the community? Please ask a new question.

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