BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HG
Calcite | Level 5 HG
Calcite | Level 5

Hi All,

Would someone please provide examples to creating Bland-altman
plots ?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
MikeZdeb
Rhodochrosite | Level 12

hi ... from what I know about Bland-Altman plots ...

* some fake data;

data test;

do _n_ = 1 to 50;

   m1 = ceil(100*ranuni(999));

   m2 = ceil(100*ranuni(999));

   output;

end;

run;

* compute means (x), difference (y);

data bla_alt;

set test;

x = mean(of m:);

y = m1 - m2;

run;

* compute mean +/- 1.96 standard deviation to add reference lines to the plot;

proc sql;

select mean(y)-1.96*std(y), mean(y)+1.96*std(y) into :lo, :hi from bla_alt;

quit;

* reset graphics options;

goptions reset=all ftext='calibri' htext=2 gunit=pct;

title1 h=4 'I THINK THIS IS A BLAND-ALTMAN PLOT' ls=2;

* whitespace around plot (if desired);

title2 a=90 ls=2;

title3 a=-90 ls=2;

footnote1 ls=1;

* a blue dot for the symbol;

symbol1 f='wingdings' v='6c'x c=blue h=2;

axis1 offset=(2,2)pct label=('MEAN');

axis2 label=(a=90 'DIFFERENCE');

* plot with dashed reference lines;

proc gplot bla_alt;

plot y*x / haxis=axis1 vaxis=axis2 vref=&lo,0,&hi lvref=3;

run;

quit;

ps attached plot looks like ... Bland–Altman plot - Wikipedia, the free encyclopedia


bland_altman.png

View solution in original post

4 REPLIES 4
MikeZdeb
Rhodochrosite | Level 12

hi ... from what I know about Bland-Altman plots ...

* some fake data;

data test;

do _n_ = 1 to 50;

   m1 = ceil(100*ranuni(999));

   m2 = ceil(100*ranuni(999));

   output;

end;

run;

* compute means (x), difference (y);

data bla_alt;

set test;

x = mean(of m:);

y = m1 - m2;

run;

* compute mean +/- 1.96 standard deviation to add reference lines to the plot;

proc sql;

select mean(y)-1.96*std(y), mean(y)+1.96*std(y) into :lo, :hi from bla_alt;

quit;

* reset graphics options;

goptions reset=all ftext='calibri' htext=2 gunit=pct;

title1 h=4 'I THINK THIS IS A BLAND-ALTMAN PLOT' ls=2;

* whitespace around plot (if desired);

title2 a=90 ls=2;

title3 a=-90 ls=2;

footnote1 ls=1;

* a blue dot for the symbol;

symbol1 f='wingdings' v='6c'x c=blue h=2;

axis1 offset=(2,2)pct label=('MEAN');

axis2 label=(a=90 'DIFFERENCE');

* plot with dashed reference lines;

proc gplot bla_alt;

plot y*x / haxis=axis1 vaxis=axis2 vref=&lo,0,&hi lvref=3;

run;

quit;

ps attached plot looks like ... Bland–Altman plot - Wikipedia, the free encyclopedia


bland_altman.png
HG
Calcite | Level 5 HG
Calcite | Level 5

Hi Mike,

Thank you very much for your help!  When I use my real data I got a warning:

WARNING: The reference line at 0.134745 on the vertical axis labeled __lvedd_diff is out of range.

How should I modify your code?

MikeZdeb
Rhodochrosite | Level 12

hi ... GPLOT chooses the min and max for the Y-axis based on a look at your data values

the calculated value for the reference line must be outside the values chosen for the bounds of the y-axis

you can use an ORDER option on an AXIS statement to control the min and max

here's an example with measurement values between 0 and 1 where the min and max on the y-axis will always be outside the ref lines

the level of ROUNDING in PROC SQL would have to be dictated by the range of your data values (I chose round to hundreths but that might not always be apppropriate)

data test;

do _n_ = 1 to 50;

   m1 = ranuni(999);

   m2 = ranuni(999);

   output;

end;

run;


data bla_alt;

set test;

x = mean(of m:);

y = m1 - m2;

run;


proc sql noprint;

select mean(y)-1.96*std(y), mean(y)+1.96*std(y),

       round(mean(y)-2.5*std(y),0.01), round(mean(y)+2.5*std(y),0.01)

into :lo, :hi , :min , :max from bla_alt;

quit;

goptions reset=all ftext='calibri' htext=2 gunit=pct;

title1 h=4 'BLAND-ALTMAN PLOT WITH AN ORDER OPTION FOR Y-AXIS' ls=2;

* whitespace;

title2 a=90 ls=2;

title3 a=-90 ls=2;

footnote1 ls=1;

symbol1 f='wingdings' v='6c'x c=blue h=2;

axis1 offset=(2,2)pct label=('MEAN');

* min and max macro variables used for range of y-axis;

axis2 label=(a=90 'DIFFERENCE') order=&min to &max;

proc gplot data=bla_alt;

plot y*x / haxis=axis1 vaxis=axis2 vref=&lo,0,&hi lvref=3;

run;

quit;


son_of_bland_altman.png
HG
Calcite | Level 5 HG
Calcite | Level 5

Hi Mike,

It works great! Thank you very much!!!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 5718 views
  • 3 likes
  • 2 in conversation