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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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