By Bob Kettlewell, Managed Services Consultant
Formats have always been a key request from SAS users, allowing users to present their data in more meaningful ways. They do not change the underlying data but can display numeric variables in different ways, for example adding pounds or dollar signs for currencies or showing SAS dates as interpretable dates. Some are included by default in SAS platforms, but users can add their own custom formats to give them the flexibility to display their data in a way that suits.
In SAS 9, formats are stored in a catalog which can contain multiple formats as well as other SAS files. These catalogs are added to a format search path which is unique to each SAS session, and when SAS encounters data that requests a format, it searches the catalogs in this path to find it. If the format is in a catalog on the search path, SAS 9 can automatically use, and assign it to the data.
SAS Viya can still use the same formats, but making them accessible to SAS Viya is not achieved in the same way. To fully utilise the functionality of formats in SAS Viya, you must first load the formats into CAS (Cloud Analytics Services).
Formats can be added into CAS in multiple ways:
Using the first two options require access to an administrator to promote the formats to CAS. However, using code, formats can be loaded without any administrator permissions.
To upload an existing format catalog (a .sas7bcat file) into CAS, the following code can be utilised from an active SAS Studio session.
/* The name of the catalog file ie. <catalog_name>.sas7bcat */ %let catalog_name = formats; /* The Path to where the format catalog is located */ %let catalog_path = C:\Formats; /* The name of the library to store the formats */ %let library_name = fmt_lib; /* libname to where the format catalog is */ libname &library_name. "&catalog_path."; /* Create temporary dataset with all formats in */ proc format lib=&library_name..&catalog_name. cntlout=temp; run; /* Open default cas session */ cas casauto; /* Load dataset of formats into cas */ proc format cntlin=temp casfmtlib='&library_name.'; run; /* Promote to global scope */ cas casauto promotefmtlib fmtlibname=&library_name. replace;
There are 3 macro variables that will need to be changed at the top of the code in order for it to run:
After these macro variables have been changed, the program will add the formats into CAS, without the need for administrator permissions.