BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
bharath86
Obsidian | Level 7
proc compare base=premig.ae compare=postmig.ae out=test novalues ;
run;

image.png

Hi,

Please find the attached sample code and output image.

 

I am trying to run a comparison between folders and all I am looking for is a simple output like this one.

 

I don't need all other summaries it prints, I just need a table as attached. How can I achieve this?

 

I have tried all the options but they seem to produce a lot of other comparisons. 

 

Please advise.

 

Thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

What do you mean by "run a comparison between folders"?

 

Proc compare compares data sets, not folders.

 

This output dataset, named Myoutputset below, will have that information. However it will have all of the output, not just that circled. That is due to the nature of ODS Output, it creates tables of the results, and in this case includes the headings and more than you want.

 

ods output comparedatasets = myoutputset;
proc compare base=premig.ae compare=postmig.ae out=test novalues ;
run;

 

 I would suggest a different approach and query the metadata that SAS keeps.

proc sql;
   create table somename as
   select *
   from dictionary.tables 
   where libname in ('PREMIG' 'POSTMIG') and memname in ('AE')
   ;
QUIT;

This will get just about anything you want to know about the properties of the two data sets. You can list the specific variables you want  such as Libname, Memname, CRdate, Moddate, Nvar, Nobs if that is all you are interested in.

This approach would let you get the summary data for many more data sets. If you have catalogs or such that have the same name as the data sets you would would to add "and memtype='DATA'. If you want the details for all of the sets in the libraries then skip the "and memname in ()" part of the code.

DICTIONARY.TABLES and others are special views of the data and have a the special location Dictionary that is NOT a library name. Proc SQL uses that special name to reference the contents. The values of Libname and Memname must be in upper case as that is how they are stored. You can look at the library SASHELP for views whose names start with V (mostly) for a data step approach.

View solution in original post

7 REPLIES 7
SASKiwi
PROC Star

A PROC CONTENTS of each dataset should provide that.

bharath86
Obsidian | Level 7

I don't think, the contents procedure would compare two datasets and print out a report as I wanted. 

ballardw
Super User

What do you mean by "run a comparison between folders"?

 

Proc compare compares data sets, not folders.

 

This output dataset, named Myoutputset below, will have that information. However it will have all of the output, not just that circled. That is due to the nature of ODS Output, it creates tables of the results, and in this case includes the headings and more than you want.

 

ods output comparedatasets = myoutputset;
proc compare base=premig.ae compare=postmig.ae out=test novalues ;
run;

 

 I would suggest a different approach and query the metadata that SAS keeps.

proc sql;
   create table somename as
   select *
   from dictionary.tables 
   where libname in ('PREMIG' 'POSTMIG') and memname in ('AE')
   ;
QUIT;

This will get just about anything you want to know about the properties of the two data sets. You can list the specific variables you want  such as Libname, Memname, CRdate, Moddate, Nvar, Nobs if that is all you are interested in.

This approach would let you get the summary data for many more data sets. If you have catalogs or such that have the same name as the data sets you would would to add "and memtype='DATA'. If you want the details for all of the sets in the libraries then skip the "and memname in ()" part of the code.

DICTIONARY.TABLES and others are special views of the data and have a the special location Dictionary that is NOT a library name. Proc SQL uses that special name to reference the contents. The values of Libname and Memname must be in upper case as that is how they are stored. You can look at the library SASHELP for views whose names start with V (mostly) for a data step approach.

bharath86
Obsidian | Level 7

I initially taught, the solution to my problem would be complex. After looking at the dictionary tables, a solution was right in front. 

I was not looking for a detailed record-level comparison. The approach with dictionary tables simplified the process. 

 

Thank you for reminding me about the dictionary tables. 

Tom
Super User Tom
Super User

See if you let ODS help you.

Turn on ODS trace. Run your PROC COMPARE.  See what output is the one that writes that dataset summary table and only select that one to print. Do you know how to use ODS trace, ODS select , ODS exclude, etc?

 

Do you know how to use ODS OUTPUT?  If so send that output to a dataset and remove the lines you don't want.

Kurt_Bremser
Super User

PROC COMPARE does not work with folders. The word "folder" is used in SAS for parts of the hierarchical structure of SAS metadata, or as a synonym for directories in the operating system's filesystem.

 

PROC COMPARE compares datasets, which are (on the physical side) files within a directory (which you can call a "folder") for which a LIBNAME has been defined.

Ksharp
Super User
ods select CompareDatasets;
proc compare base=have1 compare=have2 ;run;

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
  • 7 replies
  • 1101 views
  • 0 likes
  • 6 in conversation