Ghazal
Ghazal

Reputation: 101

SAS comparing data in a column

I'm very new to SAS and i'm trying to figure out my way around using it. I'm trying to figure out how to use the Compare procedure. Basically what I want to do is to see if the values in one column match the values in another column multiplied by 2 and count the number of mistakes. So if I have this data set:

 a b
 2 4
 1 2
 3 5

It should check whether b = 2 * a and tell me how many errors they are. I've been reading through the documentation for the compare procedure but like i said i'm very new and i can't seem to figure out how to check for this.

Upvotes: 0

Views: 1182

Answers (2)

Sean
Sean

Reputation: 1120

Proc compare compares values in two different datasets, whereas your variables are both in one dataset. The following may be simplest:

data matches errors;
    set temp;
    if b = 2 * a then output matches;
    else output errors;
run;

Upvotes: 0

data _null_
data _null_

Reputation: 9109

You could do if with PROC COMPARE but you still need to compute 2*a and you can't do that with PROC COMPARE. I would create a FLAG and summarize the FLAG. IFN function returns 1 for values that are NOT equal. PROC MEANS counts the 1's where mean is percent and sum is count of non-matching.

data comp;
   input a b;
   flag = ifn(b NE 2*a,1,0);
   cards;
 2 4
 1 2
 3 5
 ;;;;
   run;
proc means n mean sum;
   var flag;
   run;

enter image description here

Upvotes: 2

Related Questions