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!
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
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
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=¬_common &var_c;%end;
%end;
%put %nrstr(¬_common)=¬_common;
%mend get_dif;
%get_dif
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.