BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KathyD1
Calcite | Level 5

Hi,

I need to assess whether data across multiple variables matches.  At the same time I need to bypass missings (not take them into account when determining whether there's a match or non-matching data.  For example, In the data below I would want to note in the first data row that data do not match.  The second data row would be a 'match'.  Thank you!


REF1    REF2     REF3     REF4     REF5

123          .               123      124          .

    .        124             124         ,            ,

   123     123              .            .            .

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

If these are numeric then

 

data want;
     set have;
     nonmatches = var (of ref1 - ref5);
run;

If the variance is zero, then the non-missings are all equal, they all match. If the variance is greater than zero, then there is at least one mismatch among the non-missing values.

--
Paige Miller

View solution in original post

4 REPLIES 4
Astounding
PROC Star

With numeric variables, the comparison is easy:

 

if min(of ref1-ref5) ne max(of ref1-ref5) then result = 'no match';

else result='match';

ballardw
Super User

@Astounding wrote:

With numeric variables, the comparison is easy:

 

if min(of ref1-ref5) ne max(of ref1-ref5) then result = 'no match';

else result='match';


Simpler

 

if range (of ref1-ref5) = 0 then result='match';

else result = 'no match'.

 

Though I find the though of using a character result cringeworthy:

result = range(of ref1-ref5) = 0;

 

PaigeMiller
Diamond | Level 26

If these are numeric then

 

data want;
     set have;
     nonmatches = var (of ref1 - ref5);
run;

If the variance is zero, then the non-missings are all equal, they all match. If the variance is greater than zero, then there is at least one mismatch among the non-missing values.

--
Paige Miller
KathyD1
Calcite | Level 5

Thank you everyone!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1311 views
  • 2 likes
  • 4 in conversation