- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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