DATA Step, Macro, Functions and more

OUTPUT IN PDF FORMAT

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

OUTPUT IN PDF FORMAT

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
Solution
‎04-24-2017 01:38 AM
PROC Star
Posts: 7,468

Re: OUTPUT IN PDF FORMAT

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


All Replies
Contributor
Posts: 65

Re: OUTPUT IN PDF FORMAT

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;

 

Solution
‎04-24-2017 01:38 AM
PROC Star
Posts: 7,468

Re: OUTPUT IN PDF FORMAT

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

 

Super User
Posts: 19,772

Re: OUTPUT IN PDF FORMAT

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

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 144 views
  • 0 likes
  • 3 in conversation