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]

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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