Hi there,
I used this code to calculate Kappa for two observers and a whole lot of categories:
proc freq
data= A_R_IOR;
tables act_A*act_R
c_prone_A*c_prone_R
chin_A*chin_R
closed_A*closed_R
e_asy_left_A*e_asy_left_R
e_asy_right_A*e_asy_right_R
e_axial_A*e_axial_R
e_back_A*e_back_R
e_droop_A*e_droop_R
e_mov_A*e_mov_R
e_OOS_A*e_OOS_R
e_pinned_A*e_pinned_R
e_for_A*e_for_R
eyes_OOS_A*eyes_OOS_R
face_ahead_A*face_ahead_R
face_in_A*face_in_R
face_left_A*face_left_R
face_neutral_A*face_neutral_R
face_out_A*face_out_R
face_right_A*face_right_R
face_straight_A*face_straight_R
flat_side_A*flat_side_R
folded_in_A*folded_in_R
forehead_A*forehead_R
friendly_give_A*friendly_give_R
friendly_rec_A*friendly_rec_R
front_legs_OOS_A*front_legs_OOS_R
front_legs_stretched_A*front_legs_stretched_R
front_legs_tucked_A*front_legs_tucked_R
groom_self_A*groom_self_R
half_closed_A*half_closed_R
head_contact_floor_A*head_contact_floor_R
head_contact_obsticle_A*head_contact_obsticle_R
head_contact_own_body_A*head_contact_own_body_R
head_mov_LY_A*head_mov_LY_R
head_mov_S_A*head_mov_S_R
head_no_contact_A*head_no_contact_R
high_pressure_A*high_pressure_R
hostile_give_A*hostile_give_R
hostile_rec_A*hostile_rec_R
inact_A*inact_R
lying_A*lying_R
lying_on_left_A*lying_on_left_R
lying_on_right_A*lying_on_right_R
mov_frequently_S_A*mov_frequently_S_R
mov_occasionally_S_A*mov_occasionally_S_R
neck_above_horizontal_A*neck_above_horizontal_R
neck_below_horizontal_A*neck_below_horizontal_R
neck_down_A*neck_down_R
neck_horizontal_A*neck_horizontal_R
neck_middle_A*neck_middle_R
neck_mov_A*neck_mov_R
nose_angle_normal_A*nose_angle_normal_R
nose_angle_OOS_A*nose_angle_OOS_R
nose_angle_stretched_A*nose_angle_stretched_R
nose_A*nose_R
nose_pressing_A*nose_pressing_R
nothing_special_A*nothing_special_R
one__front_leg_stretched_A*one__front_leg_stretched_R
open_A*open_R
rear_leg_stretched_A*rear_leg_stretched_R
rear_legs_OOS_A*rear_legs_OOS_R
rear_legs_tucked_A*rear_legs_tucked_R
rum_no_A*rum_no_R
rum_OOS_A*rum_OOS_R
rum_yes_A*rum_yes_R
side_of_head_A*side_of_head_R
slight_touch_A*slight_touch_R
stand_fully_in_box_A*stand_fully_in_box_R
stand_half_in_box_A*stand_half_in_box_R
stand_in_alley_A*stand_in_alley_R
stereo_A*stereo_R
tail_directed_wagging_A*tail_directed_wagging_R
tail_hanging_A*tail_hanging_R
tail_lifted_straight_A*tail_lifted_straight_R
tail_not_lifted_A*tail_not_lifted_R
tail_OOS_A*tail_OOS_R
tail_OOS_lifted_A*tail_OOS_lifted_R
tail_small_wagging_A*tail_small_wagging_R
tail_strong_wagging_A*tail_strong_wagging_R
tail_tucked_between_legs_A*tail_tucked_between_legs_R
toung_rolling_A*toung_rolling_R/norow nocol nopercent;
test kappa;
run;
How do I convert what I see in the result viewer (sashtml) to an excel file? I only need the Kappa value!
Thank you 🙂
First thing, the code you show will not generate ANY kappa values. You need to use the AGREE option on the tables statement to get them.
Second which "kappa value"?
The procedure would generate two tables, one for the Test statistic and the other Kappa coefficient.
Here is the approach for learning how to select any specific table(s) for output .
First run your code with the option ODS TRACE ON/off such as
ods trace on; proc freq data=data; tables var1 * var2 / agree; test kappa; run; ods trace off;
The log will show some details about which tables were generated such as:
Output Added: ------------- Name: CrossTabFreqs Label: Cross-Tabular Freq Table Template: Base.Freq.CrossTabFreqs Path: Freq.Table1.CrossTabFreqs ------------- Output Added: ------------- Name: McNemarsTest Label: McNemar's Test Template: Base.Freq.StatFactoid Path: Freq.Table1.McNemarsTest ------------- Output Added: ------------- Name: Kappa Label: Simple Kappa Coefficient Template: Base.Freq.StatFactoid Path: Freq.Table1.Kappa ------------- Output Added: ------------- Name: KappaTest Label: Simple Kappa Test Template: Base.Freq.StatFactoid Path: Freq.Table1.KappaTest -------------
The key part you are looking for is the NAME.
You can then generate output for only the items you want by using ODS select such as:
ods select kappa; proc freq data=data; tables var1 * var2 / agree; test kappa; run;
will only generate the kappa table results. If want both the Kappa and the Kappatest use both names on the select.
To send to a different destination then you wrap the code generating the bits you want in an ODS destination "sandwich:
ods excel file="<system path>\file.xlsx" <many options may go here> <code that generates the output you want goes here can be multiple procedures > ods excel close;
That CLOSE is what terminates sending the results to the ods destination and if not present you will not get the desired output.
You can specify different or multiple ODS destinations in a single program
@rola13 wrote:
Hi ballardw,
thank you so much for your detailed response. This is exactly what I needed! I checked again, if my code without the AGREE statement also gives me the simple kappa coefficient and it goes! Why did you think I wouldn't?
Slightly different versions of SAS most likely. Mine would not generate the output without agree.
Hi rola13,
In your code, the KAPPA option in the TEST statement automatically invokes the AGREE option in the TABLES statement. (When you use only one TABLES statement, TEST statement options invoke the corresponding TABLES statement options -- documentation is here.)
The AGREE option in the TABLES statement provides kappa coefficients, standard errors and confidence limits. The KAPPA option in the TEST statement provides a kappa test (in addition to the kappa coefficients, standard errors, and confidence limits).
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.