BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sejin
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@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
Sejin
Obsidian | Level 7

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.

PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Sejin
Obsidian | Level 7

Well.. it suddenly worked

srry for waisting your time

Ksharp
Super User

Why not use 

proc means data=have cv ;

by class1 class2;

var var1 var2;

run;

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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