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

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 ?

 

1 ACCEPTED SOLUTION

Accepted Solutions
StatDave
SAS Super FREQ

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

4 REPLIES 4
Reeza
Super User

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. 

ballardw
Super User

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.

 

Tom
Super User Tom
Super User

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
StatDave
SAS Super FREQ

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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