turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Reg: Compare for matching and non matching varaibl...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-08-2010 08:01 AM

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.

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

09-08-2010 09:57 AM

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;

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;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to polingjw

09-09-2010 01:00 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

09-09-2010 06:10 AM

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 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;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

09-09-2010 10:41 AM

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]

[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]

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to polingjw

09-09-2010 01:02 AM

a