Create a SAS matrix catalog file from SAS datasets

If you want to use DAT2MAT then download it here:


Download dat2mat.sas


If you are not prompted to "Save To Disk", then right-click the link and choose "Save Link Target As..."  Otherwise, you will need to save the web page to your computer.  Make sure you save the dat2mat.sas file as a plain text file not an htm/html file.


The MAT2DAT SAS macro is a complementary SAS macro to DAT2MAT.


Disclaimer:  There is no warranty on this software either expressed or implied.  This program is released under the terms and conditions of GNU General Public License.




Programmer:  Dan Blanchette
The Carolina Population Center
The University of North Carolina
Chapel Hill, NC  USA
Developed at Research Computing at The University of North Carolina at Chapel Hill

Date:  10Jul2008
Last updated:  12Mar2009

Create a SAS matrix catalog from SAS dataset(s)


%dat2mat( input libref , matrix catalog name , output libref , names of matrices to create );



DAT2MAT creates one SAS matrix catalog file from the specified datasets and names the matrices with the specified matrix names.  This is especially useful if you have to transfer the matrix data from one operating system to another since SAS catalog files can only be read into SAS on the operating system the file was created on where SAS datasets can be read on any operating system.  To convert the SAS catalog file back to SAS datasets again, use the MAT2DAT SAS macro.  DAT2MAT is designed to process SAS datasets that were created by the MAT2DAT SAS macro or datasets that have a naming convention of:

Like for example the SAS dataset named:

would create the matrix catalog file:

with a matrix named:



NOTE:  The parameters have to be specified in the order of this list.


The libref where the input SAS dataset(s) exists.



The name of the SAS matrix catalog file (without the file extension:  ".sas7bcat") to create.  This string has to be the first string of the dataset names followed by an underscore ( _ ).



The libref where the output SAS matrix catalog file will be saved to.



Names of the SAS matrices to create.  These names have to be the end part of the SAS dataset names in the input library that start with the specified matrix catalog filename followed by and underscore ( _ ).  If no matrix names are specified then all SAS datasets in the input library that have names that start with the specified catalog name followed by an underscore ( _ ) will be processed.  So, only specify matrix names if only a subset of datasets are desired.


How to invoke DAT2MAT:

Using the DAT2MAT macro requires that you understand how to use the %include statement and that you know how to call a SAS macro.
For example, if you have copied this file to "C:\SASmacros\", then you tell SAS about this macro by adding the following line to your SAS program:
 %include "C:\SASmacros\dat2mat.sas"; 
The include statement makes SAS aware of the DAT2MAT macro which is in the file dat2mat.sas.  You call the macro by adding this to your code:
  %dat2mat( LIB_IN , CATALOG_FILE , LIB_OUT , matrix names );



   libname LIB_IN "C:\wherever your matrix_data.sas7bdat file is\";

   libname LIB_OUT "C:\wherever you want your matrix catalog file to be saved\";
   %include"c:\wherever you put dat2mat.sas\dat2mat.sas";
   %dat2mat(LIB_IN , matrix_catalog , LIB_OUT , mat1 mat2 mat3);
The above invocation of DAT2MAT expects to find the SAS datasets:
in the LIB_IN library and will create the matrix catalog file:
in the LIB_OUT library and it will contain the matrices:
     mat1 mat2 mat3
If the SAS datasets:
also exist in the input library, these datasets will not be processed by DAT2MAT because:
was not spcecified in the matrix name list and:
does not have an underscore ( _ ) following the specified matrix catalog file name.

Wink Plone Theme by Quintagroup © 2013.

Personal tools
This is themeComment for Wink theme