Adds a format library to the current CAS session. This allows user-defined formats to be used in analyses and data manipulation within CAS. Format libraries can be loaded from a caslib (as a SASHDAT file) or directly from a server path. This action is crucial for customizing data representation and reporting in Viya.
| Parameter | Description |
|---|---|
| caslib | Specifies the caslib where the format library resides. Do not specify this parameter with the path parameter. |
| fmtLibName | Specifies the format library name. The name cannot exceed 63 characters in length. |
| fmtSearch | Specifies the format library search order. Can be APPEND, INSERT, NONE, or REPLACE. Default is APPEND. |
| name | Specifies the format library name in the caslib. If adding from a SASHDAT file, the .sashdat extension is optional. Do not use with the path parameter. |
| path | Specifies the path to a format library file. The path must be readable from the server's control node. Do not use with the name or caslib parameter. |
| promote | When set to True, the format library is promoted to global scope, making it available to all sessions. Administrative rights might be required. |
| replace | When set to True, an existing format library of the same name is replaced. |
Before adding a format library to CAS, you first need to create one. A common method is to use PROC FORMAT with the CNTLOUT= option. This creates a SAS data set that contains the definition of your formats. This data set can then be saved as a SASHDAT file and loaded into CAS.
| 1 | PROC FORMAT; |
| 2 | value $genderfmt 'M'='Male' 'F'='Female'; |
| 3 | value agefmt 1-12='Child' 13-19='Teen' 20-64='Adult' 65-high='Senior'; |
| 4 | RUN; |
| 5 | |
| 6 | /* Create a control data set from the formats */ |
| 7 | LIBNAME mycas cas; |
| 8 | DATA mycas.myformats_table; |
| 9 | SET sashelp.vformat; |
| 10 | where fmtname in ('GENDERFMT', 'AGEFMT'); |
| 11 | RUN; |
This example assumes a CAS table named 'myformats_table' exists in the 'mycas' caslib (created in the data creation step). It adds this table as a format library named 'myformats' to the current session.
| 1 | |
| 2 | PROC CAS; |
| 3 | sessionProp.addFmtLib / caslib="mycas" name="myformats_table" fmtLibName="myformats"; |
| 4 | |
| 5 | RUN; |
| 6 |
This example demonstrates a complete workflow. First, it creates a format library and saves it as a SASHDAT file to a physical path accessible by the CAS server. Then, it uses `addFmtLib` with the `path` parameter to add it to the session. The `promote=true` option makes it globally available, and `replace=true` ensures any existing library with the same name is overwritten.
| 1 | LIBNAME mycas cas; |
| 2 | PROC FORMAT lib=work; |
| 3 | value $countryfmt 'US'='United States' 'CA'='Canada'; |
| 4 | RUN; |
| 5 | PROC FORMAT lib=work cntlout=work.countryctl; |
| 6 | select $countryfmt; |
| 7 | RUN; |
| 8 | DATA mycas.countryformats; |
| 9 | SET work.countryctl; |
| 10 | RUN; |
| 11 | PROC CASUTIL; |
| 12 | save casdata="countryformats" incaslib="mycas" outpath="/cas/data/casuser/countryformats.sashdat" replace; |
| 13 | QUIT; |
| 14 | PROC CAS; |
| 15 | sessionProp.addFmtLib / |
| 16 | path="/cas/data/casuser/countryformats.sashdat" |
| 17 | fmtLibName="globalformats" |
| 18 | promote=true |
| 19 | replace=true; |
| 20 | RUN; |
The marketing department needs to analyze campaign outreach results. They require custom formats to segment customers by age group and geographical region, which are not standar...
A financial institution maintains a centrally managed, large set of formats for categorizing transaction risk. This library must be available to all data scientists and analysts...
Two departments, Marketing and Fraud, have independently developed format libraries. Both libraries contain a format with the exact same name ('$STATUSFMT') but with different b...