Solved
New Contributor
Posts: 3

# HW Question | Using a macro and I'm confused as to creating the variables

I understand the RANUNI fuction but for the life of me I can't understand the three macro variables part of the question.  If you can help I would be extremely grateful!

In summary, your job here is to use the RANUNI function in conjunction with a DO loop and an OUTPUT statement to create a temporary SAS data set called agree containing 100 observations and two character variables called rater1 and rater2. (We'll use the data set to calculate the Kappa coefficient between the two raters.) Now, here are the specific requirements for the problem:

• Use a seed of 456 in your RANUNI function so that we all create the same data set.
• For each iteration of the DO loop: (1) if the value returned by the RANUNI function is less than 0.4, set rater1 to equal Yes and rater2 to equal Yes; (2) if the value returned by the RANUNI function is at least 0.4, but less than 0.5, set rater1 to equal Yes and rater2 to equal No; (3) if the value returned by the RANUNI function is at least 0.5, but less than 0.6, set rater1 to equal No and rater2 to equal Yes; and (4) if the value returned by the RANUNI function is at least 0.6, set rater1 to equal No and rater2 to equal No.
• Write the code using three macro variables called cutoff1, cutoff2, and cutoff3 so that the cutoff values of 0.4, 0.5, and 0.6 could be changed easily.
• Compute the Kappa coefficient between the two raters.

What is the Kappa coefficient when the cutoff values are set at 0.4, 0.5, and 0.6? What level of agreement does it suggest exists between the two raters? What is the Kappa coefficient when the cutoff values are set at 0.2, 0.5, and 0.8? What level of agreement does it suggest exists between the two raters then? (Hint: I recommend first getting the code to work using the values 0.4, 0.5, and 0.6. Then replace those values with the cutoff1, cutoff2, and cutoff3 macro variables.)

Accepted Solutions
Solution
‎04-29-2018 10:32 PM
Posts: 1,837

## Re: HW Question | Using a macro and I'm confused as to creating the variables

Your code seems to be correct. Better try to run it.

Add RUN; to close the data step.

BTW, you can use format to assign the cutoffs instead IF ...THEN...; ELSE ...

``````proc format lib=work;
value raterfmt
1 = 'YES'
2 = 'NO'
;
vaulue cutoff
low - &cutoff1 = '1'
&cutoff1 - &cutoff2 = '2'
&cutoff2 - &cutoff3 = '3'
&cutoff3 - high = '4'
;
run;

data agree2;
set agree1;
rater1 = put(random, cutoff.);
format rater1 raterfmt. ;
run;``````

All Replies
Posts: 1,837

## Re: HW Question | Using a macro and I'm confused as to creating the variables

[ Edited ]

To sort the results into 4 groups you have 3 cutoffs.

Using macro variable enables to assign values outside of the datastep,

thus changing cutoff values will be easy.

Use %LET cuttoff1=0.4;  to assign value to the 1st macro variable.

like:   if  result < &cutoff1 then ...

If you still have issues post the code you wrote.

New Contributor
Posts: 3

## Re: HW Question | Using a macro and I'm confused as to creating the variables

Thank you so much for your help!  This is the partial coding (part relevant with the macro).  Is this right?  I need to be able to create the second variable within the if / then statement.  Could there be an if/then/and ... else then... and repeat?

%LET cutoff1 = 0.4;
%LET cutoff2 = 0.5;
%LET cutoff3 = 0.6;

PROC FORMAT;
value raterfmt 1 = 'Yes'
2 = 'No';
RUN;

DATA agree2;
set agree1;
if random lt &cutoff1 then rater1=1;
else if random ge &cutoff1 and random le &cutoff2 then rater1=1;
else if random ge &cutoff2 and random le &cutoff3 then rater1=2;
else if random ge &cutoff3 then rater1=2;
format rater1 raterfmt.;

Solution
‎04-29-2018 10:32 PM
Posts: 1,837

## Re: HW Question | Using a macro and I'm confused as to creating the variables

Your code seems to be correct. Better try to run it.

Add RUN; to close the data step.

BTW, you can use format to assign the cutoffs instead IF ...THEN...; ELSE ...

``````proc format lib=work;
value raterfmt
1 = 'YES'
2 = 'NO'
;
vaulue cutoff
low - &cutoff1 = '1'
&cutoff1 - &cutoff2 = '2'
&cutoff2 - &cutoff3 = '3'
&cutoff3 - high = '4'
;
run;

data agree2;
set agree1;
rater1 = put(random, cutoff.);
format rater1 raterfmt. ;
run;``````
New Contributor
Posts: 3

## Re: HW Question | Using a macro and I'm confused as to creating the variables

Great - thank you so much!

☑ This topic is solved.