Hello everyone! Hope you're doing great!
I've measured 8 types objects in two diferent times, giving the first time i measured the object its variable name and, after a week, the second time i measured it i gave it the same name followed by a "2".
As an example: CMDF is the name of the object i measured the first time and CMDF2 is the same object but measured the second time.
data correlaçao_medidas;
input NLAF CMFD CFFD CMFE CFFE CMMD CFMD CMME CFME CMFD2 CFFD2 CMFE2 CFFE2 CMMD2 CFMD2 CMME2 CFME2
;
infile datalines dlm='09'x;
cards;
Laf 003/13 46.9 46.6 46.9 46.5 4.9 4.88 4.6 4.83 46.9 46.5 46.9 46.6 5.06 4.99 4.96 4.82
Laf 005/14 45 44.8 45.6 45.4 4.07 3.9 4.14 3.99 45 44.8 45.5 45.4 4.12 3.93 4.12 3.85
;
run;
This is my data. NLAF is just to know the group of each object. My real data has more than 40 "lafs", so i just brought these two to use as an example.
Considering that i got the measurements myself, with no other person measuring the objects, how do i get the intraclass correlation using SAS?
Thanks in advance!
See https://support.sas.com/kb/30/333.html#intraclass
I believe you have to rearrange your data so that the second measurement is indicated by a value of 2 in a variable named, for example, MEASUREMENT, rather than by a 2 in the variable's name.
Thanks, PaigeMiller!
I will try it out!
/*
https://support.sas.com/kb/25/031.html
https://support.sas.com/kb/30/333.html#errinvar
https://www.lexjansen.com/nesug/nesug07/sa/sa13.pdf
*/
%let path=%sysfunc(prxchange(s/[^\\]+$//,1,%sysget(SAS_EXECFILEPATH)));
options validvarname=any validmemname=extend mrecall nofmterr nonumber nodate orientation=landscape nodsnferr;
/*准备数据 */
data FAS;
input measure_id :$20. @@;
do subjid='001','002','003','004','005','006';
input score @;
output;
end;
datalines;
第一次测量 5.9 5.8 5.5 5.6 5.4 5.5
第二次测量 5.9 5.7 5.7 5.8 5.5 5.2
第三次测量 5.9 5.8 5.7 5.6 5.4 5.2
第四次测量 5.9 5.7 5.8 5.7 5.4 5.3
;
data PPS;
set FAS;
run;
/*导入宏程序*/
%include "&path.\1_macro_intracc.sas"/source;
/*自定义 模板*/
proc template;
define style styles._journal;
parent=styles.journal;
style table from output / cellpadding=0 just=l;
end;
run;
/*页眉页角*/
title j=l "(*ESC*)S={fontstyle=roman fontweight=light }申办方:xxxx"
j=r "(*ESC*)S={fontstyle=roman fontweight=light }第 (*ESC*){thispage} 页/共 (*ESC*){lastpage} 页";
title2 j=l "(*ESC*)S={fontstyle=roman fontweight=light }某药物临床三期"
j=r "(*ESC*)S={fontstyle=roman fontweight=light}数据截止日期:2012-02-14";
footnote j=l "(*ESC*)S={fontstyle=roman fontweight=light }程序: %sysget(SAS_EXECFILENAME) "
j=r " (*ESC*)S={fontstyle=roman fontweight=light}运行日期:%sysfunc(datetime(),e8601dt.) ";
options orientation=portrait leftmargin=2.54cm rightmargin=2.54cm topmargin=1.91cm bottommargin=1.91cm; /*调正页边距,横向还是纵向*/
options mprint mfile; /*注意:必须有该语句,用于导出宏产生的SAS代码*/
filename mprint "&path.\宏产生的SAS代码.txt" lrecl=2000; /*注意:必须有该语句,用于导出宏产生的SAS代码*/
/********************产生报表**********************/
ods rtf file="&path.\report.rtf" style=_journal ;
/*宏变量说明:
data 数据集名
target 用于计算 组内相关系数(ICC) 的组变量名,是模型中的第一个X变量。注意:必须为分类变量(值是离散的),可以为数值型,也可以字符型。
depvar 模型中的Y变量。注意:必须为数值型。
rater 模型中的第二个X变量。注意:必须为分类变量(值是离散的),可以为数值型,也可以字符型。
df 宏变量rater的自由度k(=df+1) .
fas_pps 说明数据是FAS 还是 PPS,影响列头的展示 ,值有 FAS,PPS,SS .....
label 项目名称.影响第一列的展示
*/
proc delete data=output;run; /*运行宏前,一定要运行该语句。*/
%intracc(data=FAS,target=subjid,depvar=score,rater=measure_id ,df=4,fas_pps=FAS ,label=中央角膜厚度 )
%intracc(data=PPS,target=subjid,depvar=score,rater=measure_id ,df=4,fas_pps=PPS ,label=中央角膜厚度 )
%intracc(data=FAS,target=subjid,depvar=score,rater=measure_id ,df=4,fas_pps=FAS ,label=眼轴长度 )
%intracc(data=PPS,target=subjid,depvar=score,rater=measure_id ,df=4,fas_pps=PPS ,label=眼轴长度 )
proc report data=output nowd spanrows style(header)={font_style=roman just=l fontsize=0.38cm}
style(report)={outputwidth=100% cellpadding=0 cellspacing=0} style(column)={just=l fontsize=0.38cm }
style={pretext="组内相关系数(ICC)" fontfamily="MYingHei_18030_C-Medium" fontweight=bold fontsize=0.38cm}
;
column proj value,fas_pps,label;
define proj/group order=data;
define label/across order=data '';
define fas_pps/across order=data '' style={just=c} ;
define value/group '';
run;
ods text="(*ESC*)S={fontsize=0.38cm fontfamily='MYingHei_18030_C-Medium' asis=on}人口学资料";
ods rtf close;
%macro intracc(data=,target=,rater=, depvar= ,df=,fas_pps=,label=);
proc glm data=&data outstat=_stats_ noprint ;
class &target &rater;
model &depvar = &target &rater ;
run;
proc sort data=_stats_;
by _name_ _SOURCE_;
run;
data want;
retain msw msb wms ems edf bms bdf jms jdf k;
set _stats_;
by _name_;
if upcase(_type_)='SS1' then delete;
if upcase(_source_)='ERROR' then do;
ems=ss/df;
edf=df;
end;
if upcase(_source_)="%upcase(&target)" then do;
bms=ss/df;
msb=bms;
bdf=df;
end;
if upcase(_source_)="%upcase(&rater)" then do;
jms=ss/df;
jdf=df;
k=&df.; /* k=df+1;*/
end;
if last._name_ then do;
msw=((ems*edf)+(jms*jdf))/(edf+jdf);
wms=msw;
n=bdf+1;
sfsingle=(bms-wms)/(bms+(k-1)*wms); /* ICC(1,1)*/
/*95% Confidence Interval for sfsingle - ICC(1,1)
Suppose that each of N subjects (targets) yields K observations.*/
F0=bms/wms;
V1=(n-1)*(k-1);
V2=n-1;
FL=F0/quantile('F',.975,V2,V1);
FU=F0*quantile('F',.975,V1,V2);
sfsingle_lower=(FL-1)/(FL+k-1); /* ICC(1,1) lower CI*/
sfsingle_upper=(FU-1)/(FU+k-1); /* ICC(1,1) upper CI*/
output;
end;
label sfsingle="Shrout-Fleiss reliability: single score"
run;
data report;
set want;
length fas_pps label proj value $ 80;
fas_pps="%upcase(&fas_pps.)";proj="&label."; label proj='指标';
label='值';value=put(sfsingle,10.3 -l);output;
label='95%置信区间';value=cats('(',put(sfsingle_lower,10.3),',',put(sfsingle_upper,10.3),')');output;
keep proj label value fas_pps;
run;
title;
proc append base=output data=report force;run;
%mend intracc;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.