Programming the statistical procedures from SAS

Geometric Mean , CI and % CV

Accepted Solution Solved
Reply
Highlighted
Occasional Contributor
Posts: 15
Accepted Solution

Geometric Mean , CI and % CV

Hello ALL,

I have this dataset called 'have':

id var1 trt avisit 

1 45     A  baseline

1 43     A  visit2

1 43     B  baseline

1 41     B  visit2

2 48     A  baseline

2 49     A  visit2

 

2 55     B  baseline

2 83     B  visit2

3 43     A  baseline

3 41     B  visit2

3 58     B  baseline

3 69     B  visit2

.

.

.

What I want to get is the table in the attached file using proc surveymeans.

I tried with this code but it doesn't work (PS: I didn't continue with relative change ... ):

 

 

proc surveymeans data=have  geomean UGMCLM LGMCLM CV  ;
var avallg;/* this variable is a log-transformed variable so it's the log of the variable var1  */
class trt avisit; 
ods output statistics=want  n=_n  geomean=_geomean UGMCLM=_UGMCLM  LGMCLM=_LGMCLM CV=_CV ;
run;

Any suggestion please ?

 


Accepted Solutions
Solution
‎01-07-2018 06:35 AM
SAS Employee
Posts: 362

Re: Geometric Mean , CI and % CV

[ Edited ]

Assuming that your response is lognormal, you could get the geometric mean estimates and your "relative change" estimates, by fitting a normal model to the log-transformed response and then use the NLEstimate macro. For example:

 

proc genmod data=have; 
class trt avisit; 
model avallg=trt*avisit/noint; 
store g;
run;
%nlestimate(instore=g, label=geoAbase, f=exp(b_p1), df=1e4)
%nlestimate(instore=g, label=geoAvisit2, f=exp(b_p2), df=1e4)
%nlestimate(instore=g, label=geoBbase, f=exp(b_p3), df=1e4)
%nlestimate(instore=g, label=geoBvisit2, f=exp(b_p4), df=1e4)
%nlestimate(instore=g, label=geoAbase, f=exp(b_p1), df=1e4)
%nlestimate(instore=g, label=RC A, f=exp(b_p2)-exp(b_p1), df=1e4)
%nlestimate(instore=g, label=RC B, f=exp(b_p4)-exp(b_p3), df=1e4)

The large df= value is used to get large sample confidence intervals.  The delta method is used to compute the confidence limits. See the macro documentation for how to use the macro and additional examples of its use for estimating linear or nonlinear functions of model parameters. 

 

A simpler alternative to get just the geometric mean estimates is to use LSMEANS in GENMOD. This uses a different method to compute the limits. See the exponentiated results in the LSMEANS table.

proc genmod data=have; 
class trt avisit; 
model avallg=trt|avisit; 
lsmeans trt*avisit / exp cl;
run;

View solution in original post


All Replies
Super User
Posts: 22,857

Re: Geometric Mean , CI and % CV

I think you're mixing the OUTPUT OUT statement from PROC MEANS with the ODS OUTPUT statement. They operate quite differently.

 

proc surveymeans data=have  geomean UGMCLM LGMCLM CV  ;
var avallg;/* this variable is a log-transformed variable so it's the log of the variable var1  */
class trt avisit; 
ods output statistics=want ;
run;

As far as I can see, there's no OUTPUT statement for PROC SURVEYMEANS and the ODS OUTPUT doesn't allow you to change names in the same step, you'll need to do that in another step. 

Super User
Posts: 13,066

Re: Geometric Mean , CI and % CV

A dataset option RENAME will change the name of the variable such as

ods output geometricmeans=geometricmeans(rename=(u1sideclgm=_ugmclm));

But you will need to know what the default variable name is to rename it.

 

Super User
Super User
Posts: 7,860

Re: Geometric Mean , CI and % CV

Make sure to request the right output table.  You can use ODS TRACE ON to see in the log the names of the outputs that your code generates. Or you can look at the manual.

http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_surveymeans_...

Let's try it with your sample data.

data have ;
 input id var1 trt $ avisit $ ;
 avallg=log(var1);
cards;
1 45     A  baseline
1 43     A  visit2
1 43     B  baseline
1 41     B  visit2
2 48     A  baseline
2 49     A  visit2
2 55     B  baseline
2 83     B  visit2
3 43     A  baseline
3 41     B  visit2
3 58     B  baseline
3 69     B  visit2
;
proc surveymeans data=have  geomean UGMCLM LGMCLM CV  ;
  var avallg;
  class trt avisit;
ods output summary=summary;
ods output statistics=statistics ;
ods output summaryPanel=summarypanel;
ods output geometricmeans=geometricmeans;
run;
data want ;
  merge summary (where=(Label1='Number of Observations'))
        statistics
        geometricmeans
  ;
  rename nValue1=_n geomean=_geomean u1sideclgm=_ugmclm l1sideclgm=_lgmclm cv=_cv ;
  drop label1 cvalue1 ;
run;
                    Var
Obs            _n   Name            _cv      _geomean      GMStdErr       _ugmclm       _lgmclm

 1      12.000000  avallg      0.016505      3.911113      0.062776      4.025492      3.799985
Solution
‎01-07-2018 06:35 AM
SAS Employee
Posts: 362

Re: Geometric Mean , CI and % CV

[ Edited ]

Assuming that your response is lognormal, you could get the geometric mean estimates and your "relative change" estimates, by fitting a normal model to the log-transformed response and then use the NLEstimate macro. For example:

 

proc genmod data=have; 
class trt avisit; 
model avallg=trt*avisit/noint; 
store g;
run;
%nlestimate(instore=g, label=geoAbase, f=exp(b_p1), df=1e4)
%nlestimate(instore=g, label=geoAvisit2, f=exp(b_p2), df=1e4)
%nlestimate(instore=g, label=geoBbase, f=exp(b_p3), df=1e4)
%nlestimate(instore=g, label=geoBvisit2, f=exp(b_p4), df=1e4)
%nlestimate(instore=g, label=geoAbase, f=exp(b_p1), df=1e4)
%nlestimate(instore=g, label=RC A, f=exp(b_p2)-exp(b_p1), df=1e4)
%nlestimate(instore=g, label=RC B, f=exp(b_p4)-exp(b_p3), df=1e4)

The large df= value is used to get large sample confidence intervals.  The delta method is used to compute the confidence limits. See the macro documentation for how to use the macro and additional examples of its use for estimating linear or nonlinear functions of model parameters. 

 

A simpler alternative to get just the geometric mean estimates is to use LSMEANS in GENMOD. This uses a different method to compute the limits. See the exponentiated results in the LSMEANS table.

proc genmod data=have; 
class trt avisit; 
model avallg=trt|avisit; 
lsmeans trt*avisit / exp cl;
run;
☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 490 views
  • 0 likes
  • 5 in conversation