Can you please help me plot in SAS? So they want to plot the estimated weight loss percentage from regression models (not the actual weight loss) by treatment groups. I have been working on this, but my figure looks wrong. Can you please help? The code I have now is:
proc mixed data=want2 method=ml;
class mrn drug (ref='0');
model weightlossn = drug2 time drug2*time / s outpred=Pred;
random intercept drug2/ sub=mrn;
run;
proc sort data=Pred;
by time;
run;
proc sgplot data=pred;
series y=pred x=time / group=drug2;
run;
Is your variable weightlossn a percentage of some sort? If not then the Predicted values will be in the original units and type of measure.
If you have a start time measurement then you likely need to create your dependent variable as a "percent change since start" for each of the subjects. Maybe.
Something like this shows what I mean:
data have; input id measure time; datalines; 1 150 0 1 149 1 1 147 2 1 145 3 2 120 0 2 123 1 2 120 2 2 118 3 ; data need; set have; retain startmeasure; by id; if first.id then do; startmeasure=measure; measurepercent=0; end; else measurepercent = (measure-startmeasure)/startmeasure; run;
The model statement would use the "measurepercent" variable. Maybe.
If your ID, individual subjects, are using combinations of "drug2" then I have no clue what would really be a good idea.
So, we don't have your data, we can't see the plot, and even if we could, you haven't explained what is wrong with it. Can you please provide that information?
Thank you, the plot doesn't come out as two lines.
Can you please show us the output from PROC MIXED and the plot? Please use the "Insert Photos" icon to include your screen captures in your reply.
I did ask for two screen captures, you only provided one.
Is your variable weightlossn a percentage of some sort? If not then the Predicted values will be in the original units and type of measure.
If you have a start time measurement then you likely need to create your dependent variable as a "percent change since start" for each of the subjects. Maybe.
Something like this shows what I mean:
data have; input id measure time; datalines; 1 150 0 1 149 1 1 147 2 1 145 3 2 120 0 2 123 1 2 120 2 2 118 3 ; data need; set have; retain startmeasure; by id; if first.id then do; startmeasure=measure; measurepercent=0; end; else measurepercent = (measure-startmeasure)/startmeasure; run;
The model statement would use the "measurepercent" variable. Maybe.
If your ID, individual subjects, are using combinations of "drug2" then I have no clue what would really be a good idea.
Your plot is showing your input data against the estimate for each data point. I don't think that's what you actually want, I suspect what you want is actually more of an effect plot, for example what is the estimate at a set of specific values, not all the input data in your data set.
See the article, "Visualize a mixed model that has repeated measures or random coefficients,"
which discusses various options.
I will add that your PROC MIXED code looks wrong: You have DRUG on the CLASS statement, but you use DRUG2 in the model.
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.