2
votes

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;
2
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

2 Answers

0
votes

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.

0
votes

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.