Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

Before and After Line Plots with Proc SGPLOT

When graphically displaying "before" and "after" values in a line plot it is often desirable to display the results for each individual but also to group then by some other characteristic by using the same line style and colour for each group. An example of this might be the representation of blood pressure measurements before and after some intervention in a clinical trial for a set of individuals who are to be further classified by their gender.

The main issue that we need to overcome when graphing this data is that there are now two classification factors to take into account (individual and gender in our example), but we can only easily classify by one. There are a number of ways of tackling this problem, but one of the easiest to implement is to introduce missing values in the response variable at strategic points in the data to cause the line to "break".

The code below generates some fictional blood pressure data, introduces some missing data for each individual and then uses Proc SGPLOT to generate the line plot. Note that the data must be appropriately sorted before the missing data is introduced and the use of the BREAK option in the SERIES statement of Proc SGPLOT. The DATALABEL option is also used to identify the ID number of each individual at the beginning and end of each line.

data bp;
input id gender $ when $ diabp @@;
datalines;
1 M BEFORE 89 1 M AFTER 81 2 M BEFORE 88 2 M AFTER 82 3 F BEFORE 84 3 F AFTER 82 4 F BEFORE 85 4 F AFTER 80
run;
data bp1; set bp; by id when notsorted; output; if last.id then do; diabp=.; output; end; run;
proc sgplot data=bp1; series x=when y=diabp / group=gender break datalabel=id; run;

201101 MJ Before and After Line Plots with Proc SGPLOT