Return to Archive

SAS Tip of the Month
September 2009

This month is a little trick with CALL EXECUTE to compare, using PROC COMPARE, all the datasets in one directory with those in another -- don't be scared about using CALL EXECUTE, it is just another tool for which we can use to make our programs more efficient.

One typical approach is to write all the write out all the PROC COMPARE call separately, as the following code demonstrates:

   libname source_data "source_data_library";
   Libname compare_data "compare_data_library";
   PROC COMPARE BASE=source.adae COMPARE=compare.adae;
   run;
   PROC COMPARE BASE=source.addm COMPARE=compare.addm;
   run;
   PROC COMPARE BASE=source.advs COMPARE=compare.advs;
   run;

For the purposes of this example, there are only three datasets in the directory we are comparing.

Now lets look at automating this a bit by getting SAS to create the list of dataset that we are comparing and using CALL EXECUTE to use this list and actually do the dataset compare.

The first thing to note that during your SAS session, SAS actually knows a lot about your data. One of the pieces of information that is available is the name of the datasets that the session has access to - this can be found in the view (this is like a window looking at a much larger picture) called VMEMBER located in the SASHELP library.

For this approach to work we have to choose one library as the master which is the directory that has the primary list of datasets that we are comparing - this will be used as the list of dataset that is going to be compared. There is also the directory that has the data we are comparing.

Now lets write some code:

   *** Lets define the location of the source and compare data;
   libname source_data "source_data_library";
   libname compare_data "compare_data_library";

   data _null_;

      *** Lets get the list of datasets in the SOURCE_DATA
          library - that getting datasets only by use of the
          MEMTYPE="DATA" statement in the WHERE clause;
      set sashelp.vmember;
      where libname="SOURCE_DATA" And memtype="DATA";

      *** And now the CALL EXECUTE - this will take the list
          of datasets in the SOURCE_DATA library and use that
          list to write the PROC COMPARE calls;
      CALL EXECUTE("proc compare base=source_data."||strip(memname)||
                   "  compare=compare_data."||strip(memname)||"; run;"); 
 
  run;

The hardest part to understand is the CALL EXECUTE, and the second is how we got the list from the VMEMBER view in the SASHELP library - note that the SASHELP library is a default SAS library that is initiated when SAS starts so there is no need to use a LIBNAME statement to define it.

Take this code and try it at your site - after a short time you will understand the code and how the CALL EXECUTE works in this example.

________________________________
Updated September 14, 2009