BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi
i am having two datasets x and y in dataset x i am having variables a,b,c,d
and in dataset y i am having variables a,b,s,d
now i want to find out how many matching variables are there for both the dataset and not matching .If matching it should be outputed to new dataset,if not compared it should be outputed to anohter dataset.IF MATCHED THE DATASETS SHOULD BE APPENDED.
5 REPLIES 5
polingjw
Quartz | Level 8
Just to make sure that I understand, you just want to determine whether the variable names match, not the data values right? If this is correct, you should look into using sashelp.vcolumn. Something like this:


data X_variables(keep=name);
set sashelp.vcolumn(where=(libname='WORK' and memname = 'X'));
data Y_variables(keep=name);
set sashelp.vcolumn(where=(libname='WORK' and memname = 'Y'));
proc sort data=X_variables; by name;
proc sort data=Y_variables; by name;

data matching nonmatching;
merge X_variables(in=inX) Y_variables(in=inY);
by name;
if inX and inY then output matching;
else output nonmatching;
run;
deleted_user
Not applicable
Thanks for your query but in non matched dataset i wnat to find the variables from which dataset they are compning from x dataset or y dataset.i wnat like this sir

data x;
input a b c;
run;

data y;
input a b d e;
run;

matched: a b
nonmatched :
variables datasetset
c x
d y
e y
polingjw
Quartz | Level 8
That can be done by keeping the memname variable from sashelp.vcolumn:

data X_variables(keep=name memname);
set sashelp.vcolumn(where=(libname='WORK' and memname = 'X'));
data Y_variables(keep=name memname);
set sashelp.vcolumn(where=(libname='WORK' and memname = 'Y'));
proc sort data=X_variables; by name;
proc sort data=Y_variables; by name;

data matching(drop=memname) nonmatching;
merge X_variables(in=inX) Y_variables(in=inY);
by name;
if inX and inY then output matching;
else output nonmatching;
run;
data_null__
Jade | Level 19
I would use PROC COMPARE for this. You can figure out how to make the output look like you want.

[pre]
data x; input a b c f:$1. ; cards;
run;
data y; input a b d e f; cards;
run;


proc compare base=x(obs=1) compare=y(obs=1) listvar novalues;
ods exclude CompareSummary;
run;
[/pre]

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1452 views
  • 1 like
  • 3 in conversation