Programming the statistical procedures from SAS

proc mixed estimate and contrast statement

Reply
Frequent Contributor
Posts: 75

proc mixed estimate and contrast statement

hello all-

how do i specify which the subject i want to use to estimate my random effects. for example say i have 160 subjects and i do:

proc mixed;
class subjects;
model y=time;
random intercept time/ sub=subjects type=un;
estimate "60th subject slope" int 1 | int 1 / sub 60;
run;

this doesnt give what i want. the only way i know to give me the 60th subject is to say

estimate "60th subject slope" int 1 | int 1 / sub 0 0 0 0.....0 1;
where we have 59 zeros and then a 1 for the 60th subject.

im assuming its the same with the contrast statement. there must be a faster and better way right?

Message was edited by: trekvana
Regular Contributor
Posts: 169

Re: proc mixed estimate and contrast statement

The only way that I know of to specify the 60th subject would be to issue 59 0 values and then a 1 for the 60th subject. I am having trouble trying to figure out why you would want to that, but that is for another day.

In order to implement something like selecting the 60th subject, I would use a macro to generate the subject specification coefficients. Accordingly, you could code:

%macro SubSpecEst(subject=);
  %let length_subj=%sysfunc(length(&subject));
  %let lastdigit=%sysfunc(substr(&subject,&length_subj));
  %if &lastdigit=1 %then %let superscript=st; %else
  %if &lastdigit=2 %then %let superscript=nd; %else
  %if &lastdigit=3 %then %let superscript=rd; %else
                                   %let superscript=th;
  estimate "&subject.&superscript. subject slope" time 1 | time 1 / subject
               %do i=1 %to %eval(&subject.-1); 0%end; 1;
%mend SubSpecEst;

(Note that I changed your intercept specification in the estimate statement to a time specification because the label indicated the slope for the 60th subject.)

With this macro, one would then write:

proc mixed;
  class subjects;
  model y=time;
  random intercept time/ sub=subjects type=un;
  %SubSpecEst(subject=60)
run;
Frequent Contributor
Posts: 75

Re: proc mixed estimate and contrast statement

Thanks Dale!

The reason I wanted to know how to do this was just in case I ever needed to know how to do that I wouldnt be scrambling at last minute to figure it out
Ask a Question
Discussion stats
  • 2 replies
  • 83 views
  • 0 likes
  • 2 in conversation