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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
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

 

COMPARE.PNG

View solution in original post

3 REPLIES 3
LinusH
Tourmaline | Level 20
Proc compare?
Data never sleeps
PeterClemmensen
Tourmaline | Level 20
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

 

COMPARE.PNG

Loko
Barite | Level 11

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1240 views
  • 4 likes
  • 4 in conversation