Help using Base SAS procedures

Reg: Compare for matching and non matching varaibles in two datsets.

Reply
N/A
Posts: 0

Reg: Compare for matching and non matching varaibles in two datsets.

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.
Regular Contributor
Posts: 171

Re: Reg: Compare for matching and non matching varaibles in two datsets.

Posted in reply to deleted_user
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;
N/A
Posts: 0

Re: Reg: Compare for matching and non matching varaibles in two datsets.

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
Regular Contributor
Posts: 171

Re: Reg: Compare for matching and non matching varaibles in two datsets.

Posted in reply to deleted_user
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;
Respected Advisor
Posts: 3,799

Re: Reg: Compare for matching and non matching varaibles in two datsets.

Posted in reply to deleted_user
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]
N/A
Posts: 0

Re: Reg: Compare for matching and non matching varaibles in two datsets.

a
Ask a Question
Discussion stats
  • 5 replies
  • 166 views
  • 1 like
  • 3 in conversation