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

Hi all, 

 

I am trying to calculate "Geom CV (%)" for one of my table as below:

 

geo_std=exp(a_std); -> Geometric Standard Deviation
log_geo_std=log(geo_std); -> log of Geometric Standard Deviation
geo_cv=sqrt(exp(log_geo_std**2)-1)*100; -> Geom CV (%)

 

Is this correct code for "Geom CV (%)"? please confirm. 

Please let me know if you want more details.

 

Thanks,

Adi

1 ACCEPTED SOLUTION

Accepted Solutions
chinna0369
Pyrite | Level 9

Hi all, 

 

my code works well here. 

 

Thanks,

Adithya

View solution in original post

12 REPLIES 12
Reeza
Super User
I don't think so, specifically, the geometric standard deviation does not mean you can just take the exponentiation of the standard deviation. For a question like this, I'd usually find a source that I trusted and then replicate their example. Then once that worked, try it on my own data.

If you had the raw data, taking the log of those values and then calculating the STD and CV would likely be correct, but I would definitely double check that.
Rick_SAS
SAS Super FREQ

See this older thread on the same topic.

chinna0369
Pyrite | Level 9

Hi all, 

 

my code works well here. 

 

Thanks,

Adithya

Reeza
Super User

@chinna0369  Please mark one of the answers as correct, not your own response. 

chinna0369
Pyrite | Level 9

Hi Reeza, 

 

Yes, the reason I used mine as answer is my code is giving correct results so if anyone can see this post then they can use the code. 

Please let me know if I am wrong.

 

Thanks,

Adi

Reeza
Super User

@chinna0369 wrote:

Hi Reeza, 

 

Yes, the reason I used mine as answer is my code is giving correct results so if anyone can see this post then they can use the code. 

Please let me know if I am wrong.

 

Thanks,

Adi


1. Your answer includes no code so no one can use the information here to provide the correct answer

2. If you're referring to the code in your initial post, then that is incorrect, that is not the correct method to get the GEOM CV(%) as per the links Rick has included.

chinna0369
Pyrite | Level 9

Below is the code I have used for my results and it works well.

 

** First fidn out Means;
proc means data=dsn;
by trt01an;
var AVAL_1;
output out=geo_stats1 n=a_n mean=a_mean std=a_std median=a_median q1=a_q1 q3=a_q3 min=a_min max=a_max;
run;

 

** then Geo stats;
data geo_stats2;
set geo_stats1;
geo_mean=exp(a_mean);
geo_std=exp(a_std);
log_geo_std=log(geo_std);
geo_cv=sqrt(exp(log_geo_std**2)-1)*100;
run;

Reeza
Super User
Did you take the log of the original variable? That step is missing from your solution.
chinna0369
Pyrite | Level 9

Yes, I am taking the log of original variable.

 

Thanks,

Adi

Reeza
Super User
Why do you take the exponent of the Standard Deviation then?
chinna0369
Pyrite | Level 9

Yes, if I don't take the exp std two times then I am getting different values. 

 

Thanks,

Adi

chinna0369
Pyrite | Level 9

This is the complete solution from starting then:

 

data chk1;
set chk;
if var not in (. 0);
var_1=log(var);
run;
proc sort; by trt; run;

** Means;
proc means data=chk1;
by trt;
var var_1;
output out=geo_stats1 n=a_n mean=a_mean std=a_std median=a_median q1=a_q1 q3=a_q3 min=a_min max=a_max;
run;

** Geo stats;
data geo_stats2;
set geo_stats1;
geo_mean=exp(a_mean);
geo_std=exp(a_std);
log_geo_std=log(geo_std);
geo_cv=sqrt(exp(log_geo_std**2)-1)*100;
run;

data geo_stats3;
set geo_stats2;
geom_meansd=strip(put(geo_mean,8.3))||"("||strip(put(geo_std,8.4))||")";
geo_cv_=strip(put(geo_cv,8.2));
ord=3;
keep trt01an geom_meansd geo_cv_ ord;
run;

 

sorry for so many replies. I will be more clear from next time. 

 

Thanks,

Adi

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 2607 views
  • 2 likes
  • 3 in conversation