2

I am comparing the evolution of plasma concentrations over time for different treatments of patients. We applied each treatment to different subjects and for each treatment we want a graph with the evolution for each subject in black, as well as for the the mean in red.

It should look like this enter image description here

but it does look like this

enter image description here

My data has variable

  • trtan and trta for treatment number and name
  • subjid for the patient receiving that treatment
  • ATPT for timepoint
  • AVAL for Individual Concentrations
  • MEAN for average Concentrations

I am using SGPLOT to produce this line plot. y axis has concentrations while x axis has time points, I am sorting data by treatment, subject and timepoint before passing to Proc SGPLOT.

Lines for indivizual subjects are fine, Issue is with mean line plot, Since dataset is sorted by subject i am getting multiple mean plots by subject as well. My requirement is to have multiple indivizual plots and an overlaying mean plot. Can anyone advise how can i solve this.

I am using below code. How can I repair it?

proc sort data = pc2;
    by trtan trta subjid atptn atpt;
run;


proc sgplot data = pc2 dattrmap = anno pad = (bottom = 20%) NOAUTOLEGEND ;

    by trtan trta;

    series x = atptn y = aval/ group = trta  
        lineattrs = (color = black thickness = 1 pattern = solid );

    series x = atptn y = mean/ group = trta attrid = trtcolor  
        lineattrs = (thickness = 2 pattern = solid );


    xaxis label= "Actual Time (h)"
          labelattrs = (size = 10)
          values = (0 12 24 36 48 72 96 120 168)
          valueattrs = (size = 10)
          grid;

    yaxis label= "Plasma Concentration (ng/mL)"
          labelattrs = (size = 10)
          valueattrs = (size = 10)
          grid;

run;
Dirk Horsten
  • 3,753
  • 4
  • 20
  • 37
Shef
  • 21
  • 3
  • To get a more specific and applicable response, you might add some example data (ideally in the form of a data step which reads in from `infile datalines;`) and/or explain more about the variables like `trtan` and `trta ` – Dirk Horsten May 21 '20 at 15:30

2 Answers2

0

This is not a problem with the mean only. Leave out the mean, ass min=-20 to your yaxis specification, and you will see the same problem.

Alternatively run this code

data pc2;
do subj = 1 to 3;
    do time = 1 to 25;
        value = 2*sin(time/3) + rand('Normal');
        output;
    end;
end;
run;
proc sgplot data=pc2;
    series x=time y=value;
run;

and you will get

The problem without a mean

The solution is to have one plot for each subject, so first sort the data by time and transpose it to have one variable subj_1 etc. for each subject.

proc sort data=pc2 out=SORTED;
    by time subj;
run;
proc transpose data=TEST out=TRANS prefix=subj_;
    by time;
    id subj;
run;

I leave it as an exercise for you to add the mean to this dataset.

Then run sgplot with a series statement per subject. To build these statements, we interrogate the meta data in dataset WORK.TRANS

proc sql;
    select distinct 'series x=time y='|| name ||'/lineattrs = (color=black)'
    into :series_statements separated by ';'
    from sasHelp.vColumn
    where libname eq 'WORK' and memName eq 'TRANS' 
      and (name like 'subj%' or name = mean;
quit;
proc sgplot data=TRANS;
    &series_statements;
run;

The result, without the mean, looks like this for my example:

enter image description here

Of course, you will have to do some graphical fine tuning.

Dirk Horsten
  • 3,753
  • 4
  • 20
  • 37
  • Thank you for your response. In data mean and aval values are greater then 0, hence Y axis do not go below 0. I want 1 graph for 1 treatment with all subject's results and 1 mean curve of all indivizual subject results. – Shef May 21 '20 at 05:20
  • The y value being positive is relevant for your statistical problem, not for the programming issue. Further, I might put more effort in your problem if you first explain the problem better, beginning with explaining the meaning of your variables. – Dirk Horsten May 21 '20 at 16:05
  • Sure,I appreciate your help. Graph represents Overlay of Individual and Mean Plasma Concentrations. X axis has ATPT variable for timepoint. On Y axis i have AVAL variable to present Individual Concentrations and a MEAN variable containing mean of all concentrations. Requirement is to plot both Individual and Mean Plasma Concentrations on single graph. There are 3 treatments, so i am expecting 3 pages for 3 treatments with each page presenting Overlay of Individual and Mean Plasma Concentrations. – Shef May 26 '20 at 07:20
  • I am using 2 series statement each for AVAL and Mean. The problem lies with sorting i think, for Individual Concentrations (AVAL) sorting needs to be done first by subjid and then ATPT to get spegatti plot, but this sorting doesn't work with Mean plot as it needs to sorted via timepoint first and therfore ia m stuck. Hope this clears the issue. Please let me know for more details. – Shef May 26 '20 at 07:20
  • Which one of trtan and trta represents the treatment and what is the other one? – Dirk Horsten May 26 '20 at 14:03
  • You should understand we are building a knowledge database here. As a by product, we help you solve your problem, not the other way around. So your question should be intelligible for other users too. – Dirk Horsten May 26 '20 at 14:08
0

We can achive it simply by taking the mean by ATPT and then instead of merging the mean record to the PK data by ATPT, you need to append the records and then you can run your code and it will give you the result you are expecting, please let me know if it does not work, it seems to have worked for me.

jkatam
  • 2,691
  • 1
  • 4
  • 12