Published on :
Administration CREATION_INTERNE

Managing user-defined formats in CAS for Viya

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The script begins by initializing a CAS session and assigning all available CAS libraries. It then sets the default active CASLIB to 'public'. The `PROC FORMAT` procedure is used to create a custom format ('dow' for days of the week) and save it to a CAS format library named 'casformats' using the `CASFMTLIB` option. `cas casauto` actions are then executed to save and promote this format library, ensuring its persistence and availability across CAS sessions. The script also includes a `PROC CAS` block that allows assuming an administrative 'SuperUser' role to modify server options. The `fmtsearch` option is updated to include the new 'casformats' library, which ensures that custom formats can be found and used by client applications, such as SAS© Visual Analytics. A check of the `fmtsearch` option is performed to confirm the change.
Data Analysis

Type : CREATION_INTERNE


The data (the 'dow' format) is created directly within the SAS script via the `VALUE` statement of `PROC FORMAT`. No external data or data from predefined libraries (like SASHELP) is used as a source for format definition.

1 Code Block
CAS Session Management
Explanation :
This block initializes a CAS session and assigns all available CASLIBs. It then sets the default active CASLIB to 'public' via the `options caslib=` statement, which influences where subsequently defined formats will be written or searched for.
Copied!
1cas;
2caslib _all_ assign;
3 
4options caslib="public";
2 Code Block
PROC FORMAT Data
Explanation :
This `PROC FORMAT` procedure defines a user-defined format named 'dow' that associates numeric values (1-7) with the names of the days of the week. The `CASFMTLIB="casformats"` option specifies that this format should be stored in a CAS format library named 'casformats', thus making it available in the CAS environment.
Copied!
1PROC FORMAT casfmtlib="casformats";
2 value dow
3 1 = 'Sunday'
4 2 = 'Monday'
5 3 = 'Tuesday'
6 4 = 'Wednesday'
7 5 = 'Thursday'
8 6 = 'Friday'
9 7 = 'Saturday';
10RUN;
3 Code Block
CAS Actions
Explanation :
This block uses `cas casauto` actions to manage the CAS format library. `savefmtlib` saves the 'dow' format to the 'casformats' library. `promotefmtlib` makes this format library available to all active CAS sessions. Finally, `listfmtranges` displays the details of the 'dow' format to verify its existence and configuration in CAS.
Copied!
1cas casauto savefmtlib fmtlibname=casformats TABLE=dow replace;
2 
3cas casauto promotefmtlib fmtlibname='casformats' replace;
4 
5cas casauto listfmtranges fmtname=dow;
4 Code Block
PROC CAS (Administration)
Explanation :
This `PROC CAS` block is used for administrative tasks. It first assumes a `SuperUser` role to allow modifications to CAS server options. Then, it uses the `configuration.setServOpt` action to modify the `fmtsearch` option, adding 'casformats' to the format search path, which is crucial for applications like SAS Visual Analytics to find and use formats defined in CAS. Finally, `configuration.getServOpt` is used to verify that the option has been updated.
Copied!
1PROC CAS;
2 ACCESSCONTROL.assumeRole / adminRole="SuperUser"; RUN;
3 configuration.setServOpt / fmtsearch = 'sassuppliedformats casformats';
4 configuration.getServOpt RESULT=new/ name="fmtsearch";
5RUN;
6QUIT;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. SPDX-License-Identifier: Apache-2.0