BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
desireatem
Pyrite | Level 9

Thank you, the plot doesn't come out as two lines.

 

 

 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
desireatem
Pyrite | Level 9

desireatem_0-1663880760731.png

 

PaigeMiller
Diamond | Level 26

I did ask for two screen captures, you only provided one.

--
Paige Miller
ballardw
Super User

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.

Reeza
Super User

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.

 

 

 

 

Ksharp
Super User
It seems you want mixed effect plot . Try EFFECTPLOT statement and @Rick_SAS wrote this blog before .
Rick_SAS
SAS Super FREQ

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 815 views
  • 4 likes
  • 6 in conversation