From: RolandRB on
On May 6, 2:57 pm, 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 are happy with the results being put in macro variables then
you can always use my macros to do this sort of thing.

160
161 data one;
162 a = 1;
163 b = 2;
164 c = 3;
165 run;
166 data two;
167 a = 11;
168 b = 22;
169 d = 4;
170 run;
171 %let match=%match(%varlist(two),%varlist(one));
172 %put common vars=&match;
common vars=a b
173 %put vars in only one=&_nomatch_;
vars in only one=c
174 %let match=%match(%varlist(one),%varlist(two));
175 %put vars in only two=&_nomatch_;
vars in only two=d
From: RolandRB on
My %compvars macro will do this as well. I had forgotten about it
temporarily.

http://www.datasavantconsulting.com/roland/compvars.sas