Solved
Contributor
Posts: 62

# Distance between two data set

Let's say I have two datasets. One has 3 variables name 1,2,3 and the other dataset has 6 variables named 1,2,3,4,5,6. Is there a quick way to compare both datasets and determine the variables that are different? In our example it would be 4,5,6.

Thanks!

Accepted Solutions
Solution
‎11-16-2016 08:17 AM
PROC Star
Posts: 1,411

## Re: Distance between two data set

``````data one;
input one two three;
datalines;
1 2 3
;

data other;
input one two three four five six;
datalines;
1 2 3 4 5 6
;

proc compare base = one compare =  other NOVALUES LISTVAR;;
run;``````

gives you

All Replies
Super User
Posts: 5,922

## Re: Distance between two data set

Proc compare?
Data never sleeps
Solution
‎11-16-2016 08:17 AM
PROC Star
Posts: 1,411

## Re: Distance between two data set

``````data one;
input one two three;
datalines;
1 2 3
;

data other;
input one two three four five six;
datalines;
1 2 3 4 5 6
;

proc compare base = one compare =  other NOVALUES LISTVAR;;
run;``````

gives you

Super Contributor
Posts: 319

## Re: Distance between two data set

Hello,

``````%macro get_dif;
%let op=%sysfunc(open(have));
%let allvars=;
%do i=1 %to  %sysfunc(attrn(&op,nvars));
%let allvars=&allvars %sysfunc(varname(&op,%eval(&i)));
%end;

%let op_C=%sysfunc(open(sashelp.class));
%let not_common=;
%do i=1 %to %sysfunc(attrn(&op_C,nvars));
%let var_c=%sysfunc(varname(&op_C,%eval(&i)));
%if %sysfunc(find(&allvars,&var_c)) eq 0 %then
%do;%let not_common=&not_common &var_c;%end;
%end;
%put %nrstr(&not_common)=&not_common;
%mend get_dif;
%get_dif``````
🔒 This topic is solved and locked.