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 . . .
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.
With numeric variables, the comparison is easy:
if min(of ref1-ref5) ne max(of ref1-ref5) then result = 'no match';
else result='match';
@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;
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.
Thank you everyone!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.