From: Amar Mundankar on
Hi All,
I have following datasets.
data one;
a = 1;
b = 2;
c = 3;
run;
data two;
a = 11;
b = 22;
d = 4;
run;

I want to compare dataset one and two. While comparing I dont need to
take number of observations into consideration.
I want to find out only the variables names that are either common in
both datasets or variables present in only any of the datasets.
I want the following outputs.
1) dataset with one variable that will list the variables common in
both datasets.
o/p: Comm_Var
a
b
2) Dataset with 1 Variable that will list the variables only present
in Base Dataset i.e dataset one.
o/p: Var_in_only_One
c
3) Dataset with 1 Variable that will list the variables only present
in Compare Dataset i.e dataset two.
o/p: Var_in_only_two
d

I went through the SAS Manual for PROC COMPARE. I found that,
LISTBASEVAR option can be used to find out the variables that are
present in only base datasets. But i was not able to output that list
in dataset.

Please help.
Thanks in Advance.

Thanks and Regards,
Amar Mundankar.
From: data _null_; on
On May 6, 7:57 am, Amar Mundankar <amarmundan...(a)gmail.com> wrote:
> Hi All,
> I have following datasets.
> data one;
>         a = 1;
>         b = 2;
>         c = 3;
> run;
> data two;
>                      a = 11;
>         b = 22;
>         d = 4;
> run;
>
> I want to compare dataset one and two. While comparing I dont need to
> take number of observations into consideration.
> I want to find out only the variables names that are either common in
> both datasets or variables present in only any of the datasets.
> I want  the following  outputs.
> 1) dataset with one variable  that will list the variables common in
> both datasets.
>    o/p:   Comm_Var
>                  a
>                  b
> 2) Dataset with 1 Variable that will list the variables only present
> in Base Dataset i.e dataset one.
>    o/p:    Var_in_only_One
>                    c
> 3) Dataset with 1 Variable that will list the variables only present
> in Compare Dataset i.e dataset two.
>    o/p:    Var_in_only_two
>                    d
>
> I went through the SAS Manual for PROC COMPARE. I found that,
> LISTBASEVAR option can be used to find out the variables that are
> present in only base datasets. But  i was not able to output that list
> in dataset.
>
> Please help.
> Thanks in Advance.
>
> Thanks and Regards,
> Amar Mundankar.

This might be what you want.

proc compare base=one(obs=0) compare=two(obs=0) novalues listvar
nosummary;
run;
From: Ya on
On May 6, 5:57 am, Amar Mundankar <amarmundan...(a)gmail.com> wrote:
> Hi All,
> I have following datasets.
> data one;
>         a = 1;
>         b = 2;
>         c = 3;
> run;
> data two;
>                      a = 11;
>         b = 22;
>         d = 4;
> run;
>
> I want to compare dataset one and two. While comparing I dont need to
> take number of observations into consideration.
> I want to find out only the variables names that are either common in
> both datasets or variables present in only any of the datasets.
> I want  the following  outputs.
> 1) dataset with one variable  that will list the variables common in
> both datasets.
>    o/p:   Comm_Var
>                  a
>                  b
> 2) Dataset with 1 Variable that will list the variables only present
> in Base Dataset i.e dataset one.
>    o/p:    Var_in_only_One
>                    c
> 3) Dataset with 1 Variable that will list the variables only present
> in Compare Dataset i.e dataset two.
>    o/p:    Var_in_only_two
>                    d
>
> I went through the SAS Manual for PROC COMPARE. I found that,
> LISTBASEVAR option can be used to find out the variables that are
> present in only base datasets. But  i was not able to output that list
> in dataset.
>
> Please help.
> Thanks in Advance.
>
> Thanks and Regards,
> Amar Mundankar.

If you want a dataset, you can use out=xx option, but it won't tell
you
which variable is in base but not in compare. You can get that kind of
information with ods output statment, though the dataset is not
quite useful without futhuer manipulation:

ods trace on;
ods output CompareVariables=vardiff;

proc compare data=one compare=two;
run;

proc print data=vardiff;
run;

Obs type batch

1 h The COMPARE Procedure
2 h Comparison of WORK.ONE with WORK.TWO
3 h (Method=EXACT)
4 h
5 h Listing of Variables in WORK.ONE but not in WORK.TWO
6 d
7 h Variable Type Length
8 h
9 d c Num 8
10 d
11 d
12 h Listing of Variables in WORK.TWO but not in WORK.ONE
13 d
14 h Variable Type Length
15 h
16 d d Num 8

Ya
From: Ya on
On May 6, 8:28 am, Ya <huang8...(a)gmail.com> wrote:
> On May 6, 5:57 am, Amar Mundankar <amarmundan...(a)gmail.com> wrote:
>
>
>
>
>
> > Hi All,
> > I have following datasets.
> > data one;
> >         a = 1;
> >         b = 2;
> >         c = 3;
> > run;
> > data two;
> >                      a = 11;
> >         b = 22;
> >         d = 4;
> > run;
>
> > I want to compare dataset one and two. While comparing I dont need to
> > take number of observations into consideration.
> > I want to find out only the variables names that are either common in
> > both datasets or variables present in only any of the datasets.
> > I want  the following  outputs.
> > 1) dataset with one variable  that will list the variables common in
> > both datasets.
> >    o/p:   Comm_Var
> >                  a
> >                  b
> > 2) Dataset with 1 Variable that will list the variables only present
> > in Base Dataset i.e dataset one.
> >    o/p:    Var_in_only_One
> >                    c
> > 3) Dataset with 1 Variable that will list the variables only present
> > in Compare Dataset i.e dataset two.
> >    o/p:    Var_in_only_two
> >                    d
>
> > I went through the SAS Manual for PROC COMPARE. I found that,
> > LISTBASEVAR option can be used to find out the variables that are
> > present in only base datasets. But  i was not able to output that list
> > in dataset.
>
> > Please help.
> > Thanks in Advance.
>
> > Thanks and Regards,
> > Amar Mundankar.
>
> If you want a dataset, you can use out=xx option, but it won't tell
> you
> which variable is in base but not in compare. You can get that kind of
> information with ods output statment, though the dataset is not
> quite useful without futhuer manipulation:
>
> ods trace on;
> ods output CompareVariables=vardiff;
>
> proc compare data=one compare=two;
> run;
>
> proc print data=vardiff;
> run;
>
> Obs    type    batch
>
>   1     h                      The COMPARE Procedure
>   2     h              Comparison of WORK.ONE with WORK.TWO
>   3     h                         (Method=EXACT)
>   4     h
>   5     h      Listing of Variables in WORK.ONE but not in WORK.TWO
>   6     d
>   7     h                     Variable  Type  Length
>   8     h
>   9     d                     c         Num        8
>  10     d
>  11     d
>  12     h      Listing of Variables in WORK.TWO but not in WORK.ONE
>  13     d
>  14     h                     Variable  Type  Length
>  15     h
>  16     d                     d         Num        8
>
> Ya- Hide quoted text -
>
> - Show quoted text -

Here is a better one, if you only want to variable name difference:

proc sql;
create table namediff as
select a.*,b.*
from (select name as onename
from dictionary.columns
where libname='WORK' and upcase(memname)='ONE') a
full join
(select name as twoname
from dictionary.columns
where libname='WORK' and upcase(memname)='TWO') b
on onename = twoname
;

proc print data=namediff;
run;

Obs onename twoname

1 a a
2 b b
3 c
4 d
From: Amar Mundankar on
On May 6, 11:51 am, Ya <huang8...(a)gmail.com> wrote:
> On May 6, 8:28 am, Ya <huang8...(a)gmail.com> wrote:
>
>
>
>
>
> > On May 6, 5:57 am, Amar Mundankar <amarmundan...(a)gmail.com> wrote:
>
> > > Hi All,
> > > I have following datasets.
> > > data one;
> > >         a = 1;
> > >         b = 2;
> > >         c = 3;
> > > run;
> > > data two;
> > >                      a = 11;
> > >         b = 22;
> > >         d = 4;
> > > run;
>
> > > I want to compare dataset one and two. While comparing I dont need to
> > > take number of observations into consideration.
> > > I want to find out only the variables names that are either common in
> > > both datasets or variables present in only any of the datasets.
> > > I want  the following  outputs.
> > > 1) dataset with one variable  that will list the variables common in
> > > both datasets.
> > >    o/p:   Comm_Var
> > >                  a
> > >                  b
> > > 2) Dataset with 1 Variable that will list the variables only present
> > > in Base Dataset i.e dataset one.
> > >    o/p:    Var_in_only_One
> > >                    c
> > > 3) Dataset with 1 Variable that will list the variables only present
> > > in Compare Dataset i.e dataset two.
> > >    o/p:    Var_in_only_two
> > >                    d
>
> > > I went through the SAS Manual for PROC COMPARE. I found that,
> > > LISTBASEVAR option can be used to find out the variables that are
> > > present in only base datasets. But  i was not able to output that list
> > > in dataset.
>
> > > Please help.
> > > Thanks in Advance.
>
> > > Thanks and Regards,
> > > Amar Mundankar.
>
> > If you want a dataset, you can use out=xx option, but it won't tell
> > you
> > which variable is in base but not in compare. You can get that kind of
> > information with ods output statment, though the dataset is not
> > quite useful without futhuer manipulation:
>
> > ods trace on;
> > ods output CompareVariables=vardiff;
>
> > proc compare data=one compare=two;
> > run;
>
> > proc print data=vardiff;
> > run;
>
> > Obs    type    batch
>
> >   1     h                      The COMPARE Procedure
> >   2     h              Comparison of WORK.ONE with WORK.TWO
> >   3     h                         (Method=EXACT)
> >   4     h
> >   5     h      Listing of Variables in WORK.ONE but not in WORK.TWO
> >   6     d
> >   7     h                     Variable  Type  Length
> >   8     h
> >   9     d                     c         Num        8
> >  10     d
> >  11     d
> >  12     h      Listing of Variables in WORK.TWO but not in WORK.ONE
> >  13     d
> >  14     h                     Variable  Type  Length
> >  15     h
> >  16     d                     d         Num        8
>
> > Ya- Hide quoted text -
>
> > - Show quoted text -
>
> Here is a better one, if you only want to variable name difference:
>
> proc sql;
> create table namediff as
> select a.*,b.*
> from (select name as onename
>       from dictionary.columns
>       where libname='WORK' and upcase(memname)='ONE') a
>       full join
>      (select name as twoname
>       from dictionary.columns
>       where libname='WORK' and upcase(memname)='TWO') b
>   on onename = twoname
> ;
>
> proc print data=namediff;
> run;
>
> Obs    onename    twoname
>
>  1        a          a
>  2        b          b
>  3        c
>  4                   d- Hide quoted text -
>
> - Show quoted text -

Hi Ya,
Thanks a lot. This will definitely help me.

Thanks and Regards,
Amar Mundankar.