BookmarkSubscribeRSS Feed
ArchanaSudhir
Obsidian | Level 7

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

3 REPLIES 3
Reeza
Super User

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.

PGStats
Opal | Level 21

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
Steelers_In_DC
Barite | Level 11

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1176 views
  • 0 likes
  • 4 in conversation