## Comparison between two variable........

Solved
Occasional Contributor
Posts: 8

# Comparison between two variable........

Hi Everyone,

I have the Data in the below structure, I just want to check A variable numbers in B variable List. If the A variable Number not found in B variable I need that non matching record in output.

 Sno A B 1 1 1,2,3,4,5,6,7,8,9,10 2 2 1,2,3,4,5,6,7,8,9,10 3 4 1,2,3,4,5,6,7,8,9,10 4 5 1,2,3,4,5,6,7,8,9,10 5 1,2 1,2,3,4,5,6,7,8,9,10 6 2,6 1,2,3,4,5,6,7,8,9,10 7 3,8 1,2,3,4,5,6,7,8,9,10 8 0,11 1,2,3,4,5,6,7,8,9,10 9 12,8,18 1,2,3,4,5,6,7,8,9,10

Note;- Both variables in Character.

Accepted Solutions
Solution
‎04-18-2015 10:06 PM
Posts: 5,540

## Re: Comparison between two variable........

A simple datastep approach :

data have;

length A B \$32;

input Sno A B;

datalines;

1 1 1,2,3,4,5,6,7,8,9,10

2 2 1,2,3,4,5,6,7,8,9,10

3 4 1,2,3,4,5,6,7,8,9,10

4 5 1,2,3,4,5,6,7,8,9,10

5 1,2 1,2,3,4,5,6,7,8,9,10

6 2,6 1,2,3,4,5,6,7,8,9,10

7 3,8 1,2,3,4,5,6,7,8,9,10

8 0,11 1,2,3,4,5,6,7,8,9,10

9 12,8,18 1,2,3,4,5,6,7,8,9,10

;

data absent;

length missNumber \$12;

set have;

do i = 1 to countw(A);

missNumber = scan(A, i, ",");

if findw(B, missNumber, ",", "t") = 0 then do;

output;

leave; /* Remove this statement to get all missing numbers */

end;

end;

keep Sno missNumber;

run;

proc print data=absent noobs; run;

PG

PG

All Replies
Solution
‎04-18-2015 10:06 PM
Posts: 5,540

## Re: Comparison between two variable........

A simple datastep approach :

data have;

length A B \$32;

input Sno A B;

datalines;

1 1 1,2,3,4,5,6,7,8,9,10

2 2 1,2,3,4,5,6,7,8,9,10

3 4 1,2,3,4,5,6,7,8,9,10

4 5 1,2,3,4,5,6,7,8,9,10

5 1,2 1,2,3,4,5,6,7,8,9,10

6 2,6 1,2,3,4,5,6,7,8,9,10

7 3,8 1,2,3,4,5,6,7,8,9,10

8 0,11 1,2,3,4,5,6,7,8,9,10

9 12,8,18 1,2,3,4,5,6,7,8,9,10

;

data absent;

length missNumber \$12;

set have;

do i = 1 to countw(A);

missNumber = scan(A, i, ",");

if findw(B, missNumber, ",", "t") = 0 then do;

output;

leave; /* Remove this statement to get all missing numbers */

end;

end;

keep Sno missNumber;

run;

proc print data=absent noobs; run;

PG

PG
Occasional Contributor
Posts: 8

## Re: Comparison between two variable........

Thanks a lot, It's working Fine.

🔒 This topic is solved and locked.