BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
molla
Fluorite | Level 6

Hii ,I have two datasets,I need to compare those two datasets and get the variables list that are common, not common  and get that in a pdf format,

for example I have a dataset1 with the follwing varaibles:

id name manager

dataset2 with the following variables:

id manager managerid

I need the output as

 commonvaraibles      notcommonvariables

   id                                  managerid

   manager                       name

I dont have much knowledge on ODS,Pls helpme regarding this.

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

I think that the following comes awfully close to what you want:

 

data dataset1;
   input id $ name manager  $;
   cards;
1 john joe
2 mary judy
;
   
data dataset2;
  input id manager $ managerid;
  cards;
1 tom 1
2 mary 6
;

proc contents data=dataset1 noprint out=out1(keep=name);
run;
proc contents data=dataset2 noprint out=out2(keep=name);
run;

data commonvars (drop=name);
  merge out1(in=a) out2(in=b);
  by name;
  if a and b then commonvariables=name;
  else notcommonvariables=name;
run;

ods pdf file='/folders/myfolders/test.pdf';
proc print data=commonvars;
run;
ods pdf close;

 

Art, CEO, AnalystFinder.com

 

View solution in original post

3 REPLIES 3
molla
Fluorite | Level 6

I got the common variables :

proc contents data=dataset1 noprint out=out1(keep=name);

run;

proc contents data=dataset2 noprint out=out1(keep=name);

run;

data commonvars;

merge out1(in=a) out2(in=b);

by name;

if a and b then output;

run;

 

art297
Opal | Level 21

I think that the following comes awfully close to what you want:

 

data dataset1;
   input id $ name manager  $;
   cards;
1 john joe
2 mary judy
;
   
data dataset2;
  input id manager $ managerid;
  cards;
1 tom 1
2 mary 6
;

proc contents data=dataset1 noprint out=out1(keep=name);
run;
proc contents data=dataset2 noprint out=out2(keep=name);
run;

data commonvars (drop=name);
  merge out1(in=a) out2(in=b);
  by name;
  if a and b then commonvariables=name;
  else notcommonvariables=name;
run;

ods pdf file='/folders/myfolders/test.pdf';
proc print data=commonvars;
run;
ods pdf close;

 

Art, CEO, AnalystFinder.com

 

Reeza
Super User

You should look into PROC COMPARE for this solution rather than hard code it. This is how your code should look, but you probably want to add some options to PROC COMPARE to limit the output to what you're interested in. 

 

ods pdf file='myfile.pdf';

proc compare data=one compare=two;
run;

ods pdf close;

Here's an example of how I deal with this, when having multiple data sets and need to identify which variables are present in which datasets.

 

https://gist.github.com/statgeek/3b57ae085d9f7a36a2d95c15f04e72e6

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4844 views
  • 0 likes
  • 3 in conversation