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

Hi,

 

I am a little stuck with creating a Bland-Altmann plot.

 

I have used the following script : https://www.tutorialspoint.com/sas/sas_bland_altman_analysis.htm

However when I create the graph, no upper limit or mean reference line is displayed.

 

Here is the code I have used and attached you can find the values for the 2 methos I wish to compare :

 

************************************************

** Get the mean and standard deviation of the **

** difference Method1-Method2. **

************************************************;

proc means data=diffs mean std noprint;

var diff_carb;

output out=mdiff mean=mdiff_carb

std=sddiff_carb;

run;

proc print data = mdiff ;

run;

 

 

*************************************************

** Merge the mean and standard deviation of the **

** difference with each observation in the **

** original data file. **

*************************************************;

data datafile2;

if _n_=1 then set mdiff;

set diffs;

lldiffm1m22=mdiff_carb-(2*sddiff_carb);

uldiffm1m22=mdiff_carb+(2*sddiff_carb);

drop _freq_ _type_;

run;

proc print data = datafile2;

run;

 

 

********************************************************************

** Create the Bland Altman Plot with **

** scatter of the difference vs the mean for each observation **

** a reference line at 0 in solid blue **

** a reference line at the mean of the difference in solid red **

** a reference line at +/- 2SD of the mean of the difference in **

** dashed red **

********************************************************************;

proc sgplot data=datafile2;

scatter x=mean_carb y=diff_carb;

refline uldiffm1m22 / axis=y lineattrs=(color=red pattern=4 thickness=2pt) label = "95% upper limit" ;

refline lldiffm1m22 / axis=y lineattrs=(color=red pattern=4 thickness=2pt) label = "95% lower limit" ;

refline mdiff_carb / axis=y lineattrs=(color=red thickness=2pt) label = " mean difference " ;

refline 0 / axis=y lineattrs=(color=blue thickness=2pt) label = "zero bias ";

yaxis label='Difference (MFPQC-Nubel)';

yaxis values = (-95 35 ) ;

xaxis label='Mean (MFPQC+Nubel)/2';

title 'Bland-Altman Plot of Difference (MFPQC-Nubel) vs Mean';

run;

 

Thank you!!

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @CE_SAS and welcome to the SAS Support Communities!

 

You have just clipped the upper limit (40.3373) by specifying 35 as the maximum value in your y-axis specification (values = (-95 35)). How about something like values = (-100 to 50 by 10) to cover the full range of values including the limits?

 

Another issue is that the labels of three reference lines are not displayed. Reason: You specify variables for the reference values, which would require variables for the labels as well. I'd prefer the technique presented in your tutorial: Write the reference values into macro variables and then refer to them (like &mdiff_carb) in the REFLINE statements. Thus you don't need dataset DATAFILE2 with all its redundant values. Using your PROC MEANS output dataset you can create the macro variables as follows:

data _null_;
set mdiff;
call symputx('mdiff_carb',  mdiff_carb);
call symputx('lldiffm1m22', mdiff_carb-(2*sddiff_carb));
call symputx('uldiffm1m22', mdiff_carb+(2*sddiff_carb));
run;

Use data=diffs in the PROC SGPLOT statement and Insert the three ampersands (&) in the REFLINE statements and the three labels will be shown (with the corrected y-axis specification).

 

For future posts please note that many people here will not download attached MS Office files because of security concerns. (Others, like me, don't even have Word or Excel installed on their SAS workstations.) The preferred way of providing sample data is a DATA step with CARDS or DATALINES statement. See How to create a data step version of your data for useful instructions.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @CE_SAS and welcome to the SAS Support Communities!

 

You have just clipped the upper limit (40.3373) by specifying 35 as the maximum value in your y-axis specification (values = (-95 35)). How about something like values = (-100 to 50 by 10) to cover the full range of values including the limits?

 

Another issue is that the labels of three reference lines are not displayed. Reason: You specify variables for the reference values, which would require variables for the labels as well. I'd prefer the technique presented in your tutorial: Write the reference values into macro variables and then refer to them (like &mdiff_carb) in the REFLINE statements. Thus you don't need dataset DATAFILE2 with all its redundant values. Using your PROC MEANS output dataset you can create the macro variables as follows:

data _null_;
set mdiff;
call symputx('mdiff_carb',  mdiff_carb);
call symputx('lldiffm1m22', mdiff_carb-(2*sddiff_carb));
call symputx('uldiffm1m22', mdiff_carb+(2*sddiff_carb));
run;

Use data=diffs in the PROC SGPLOT statement and Insert the three ampersands (&) in the REFLINE statements and the three labels will be shown (with the corrected y-axis specification).

 

For future posts please note that many people here will not download attached MS Office files because of security concerns. (Others, like me, don't even have Word or Excel installed on their SAS workstations.) The preferred way of providing sample data is a DATA step with CARDS or DATALINES statement. See How to create a data step version of your data for useful instructions.

CE_SAS
Fluorite | Level 6

Thanks a lot!

 

It works great.

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1094 views
  • 1 like
  • 2 in conversation