DATA Step, Macro, Functions and more

2 dataset, list different observations

Reply
Contributor
Posts: 53

2 dataset, list different observations

HI,

 

I have 2 datasets a and b.

 

A has 2155 observations and 15 variables. (Product of a left join)

 

B has 2171 observations and 12 variables.(Product of a left join)

 

ANd only 5 variables are common to both the datasets.

 

How to list the extra varables in the dataset B?

 

Thanks,

Archana

Super User
Posts: 17,829

Re: 2 dataset, list different observations

[ Edited ]

Look at Proc Compare OR look into SASHELP.VTABLE for the column names from each table, variables that aren't duplicate are unique to each table.

Respected Advisor
Posts: 4,649

Re: 2 dataset, list different observations

Dataset variable names are in pseudo-table dictionary.columns:

 

proc sql;
select name from dictionary.columns
where libname="WORK" and memname="B" and 
    name not in (
        select name from dictionary.columns
        where libname="WORK" and memname="A");
quit;
PG
Valued Guide
Posts: 858

Re: 2 dataset, list different observations

This will pull only the variables that are in B and not A:

 

data a;
input var1 var2;
cards;
1 2
;
run;

data b;
input var1 var2 var3;
cards;
1 2 3
;
run;

proc transpose data=a out=tran_a (keep=_NAME_);

proc transpose data=b out=tran_b (keep=_NAME_);

data a_vars b_vars both_vars;
merge tran_a(in=a)
      tran_b(in=b);
by _NAME_;
if a and not b then output a_vars;
if b and not a then output b_vars;
if a and b then output both_vars;
run;

proc sql noprint;
select _NAME_
into :var_names
separated by ','
from b_vars;

proc sql;
create table want as
select &var_names
from b;

Ask a Question
Discussion stats
  • 3 replies
  • 161 views
  • 0 likes
  • 4 in conversation