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

After fitting a model (e.g. proc mixed) I now wish to make predictions of the mean and 95% CI using LSMEANS statement and option AT. The AT option allows many regressors but only 1 value each.

 

I have made an external dataset of fixed values for regressors.

I would like pass each row of regressor values to the lsmeans/at statement.

 

Is there any way of getting the lsmeans statement (within proc mixed) to accept the matrix of regressor values?

If not, and I have to (somehow) use a loop, please could you tell or point me to a resource that provides me with code for this complicated task of passing data row-by-row from an external dataset to the scalar lsmeans/at statement.

 

Thank you for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @treetop,

 

Using CALL EXECUTE you could create one LSMEANS statement per observation in your external dataset.

 

Example:

/* Create test dataset with regressor values */

data regr;
input r s t;
cards;
1.2 0.3 -0.5
1.5 0.7  0.1
;

/* Call PROC MIXED with one LSMEANS statement per obs. in dataset REGR */

data _null_;
set regr end=last;
if _n_=1 then
call execute('proc mixed data=test;'
          || 'class a;'
          || 'model y = a r s t r*s;');
call execute('lsmeans a / cl at (r--t)=('||catx(' ', of r--t)||');');
if last then
call execute('run;');
run;

This would create and execute the following PROC MIXED code:

proc mixed data=test;class a;model y = a r s t r*s;
lsmeans a / cl at (r--t)=(1.2 0.3 -0.5);
lsmeans a / cl at (r--t)=(1.5 0.7 0.1);
run;

Just adapt the PROC MIXED code and the regressor variable names and values to your requirements.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @treetop,

 

Using CALL EXECUTE you could create one LSMEANS statement per observation in your external dataset.

 

Example:

/* Create test dataset with regressor values */

data regr;
input r s t;
cards;
1.2 0.3 -0.5
1.5 0.7  0.1
;

/* Call PROC MIXED with one LSMEANS statement per obs. in dataset REGR */

data _null_;
set regr end=last;
if _n_=1 then
call execute('proc mixed data=test;'
          || 'class a;'
          || 'model y = a r s t r*s;');
call execute('lsmeans a / cl at (r--t)=('||catx(' ', of r--t)||');');
if last then
call execute('run;');
run;

This would create and execute the following PROC MIXED code:

proc mixed data=test;class a;model y = a r s t r*s;
lsmeans a / cl at (r--t)=(1.2 0.3 -0.5);
lsmeans a / cl at (r--t)=(1.5 0.7 0.1);
run;

Just adapt the PROC MIXED code and the regressor variable names and values to your requirements.

treetop
Calcite | Level 5
Great thanks to FreelanceReinhard for your help, this worked fantastic!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 1302 views
  • 2 likes
  • 2 in conversation