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.
Thanks for reading the thread.
@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).
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.
Show us what you get. Show us what you want.
Well.. it suddenly worked
srry for waisting your time
Why not use
proc means data=have cv ;
by class1 class2;
var var1 var2;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.