sessionProp addFmtLib

Edge Case: Resolving Format Name Conflicts with fmtSearch

Scénario de test & Cas d'usage

Business Context

Two departments, Marketing and Fraud, have independently developed format libraries. Both libraries contain a format with the exact same name ('$STATUSFMT') but with different business meanings. An analyst needs to combine data from both domains and must control which format definition is used. This scenario tests the `fmtSearch` parameter ('INSERT' vs 'APPEND') to manage the format search order and resolve name conflicts.
About the Set : sessionProp

Configuration of session properties.

Discover all actions of sessionProp
Data Preparation

Create two distinct format libraries (Marketing and Fraud) with a conflicting format name '$STATUSFMT'.

Copied!
1/* 1. Marketing Formats */
2PROC FORMAT;
3 value $statusfmt 'A'='Active Customer' 'I'='Inactive Customer';
4RUN;
5DATA work.mktg_ctl; SET sashelp.vformat; where fmtname='$STATUSFMT'; RUN;
6 
7/* 2. Fraud Formats */
8PROC FORMAT;
9 value $statusfmt 'A'='Approved' 'D'='Denied';
10RUN;
11DATA work.fraud_ctl; SET sashelp.vformat; where fmtname='$STATUSFMT'; RUN;
12 
13/* 3. Load control tables to CAS */
14PROC CASUTIL;
15 load DATA=work.mktg_ctl outcaslib='casuser' casout='mktg_formats_table' replace;
16 load DATA=work.fraud_ctl outcaslib='casuser' casout='fraud_formats_table' replace;
17QUIT;
18 
19/* 4. Create test data */
20DATA work.test_data; INPUT status_code $; DATALINES;
21A
22I
23D
24; RUN;
25PROC CASUTIL; load DATA=work.test_data outcaslib='casuser' casout='status_codes' replace; QUIT;

Étapes de réalisation

1
Test 'INSERT': Load Marketing lib, then INSERT Fraud lib. The Fraud format should take precedence.
Copied!
1PROC CAS;
2 sessionProp.addFmtLib / caslib='casuser' name='mktg_formats_table' fmtLibName='MktgLib';
3 sessionProp.addFmtLib / caslib='casuser' name='fraud_formats_table' fmtLibName='FraudLib' fmtSearch='INSERT';
4RUN;
5 
6 /* Apply format - should use Fraud's definition */
7 fedsql.execDirect / query='select status_code, put(status_code, \'$STATUSFMT.\') as FormattedStatus from casuser.status_codes';
8RUN;
2
Test 'APPEND' (Default): In a new session, load Fraud lib, then APPEND Marketing lib. The Fraud format should still take precedence as it was loaded first.
Copied!
1PROC CAS; /* Assumes a new session */
2 sessionProp.addFmtLib / caslib='casuser' name='fraud_formats_table' fmtLibName='FraudLib';
3 sessionProp.addFmtLib / caslib='casuser' name='mktg_formats_table' fmtLibName='MktgLib' fmtSearch='APPEND';
4RUN;
5 
6 /* Apply format - should use Fraud's definition */
7 fedsql.execDirect / query='select status_code, put(status_code, \'$STATUSFMT.\') as FormattedStatus from casuser.status_codes';
8RUN;

Expected Result


For Step 1, the result set must show the Fraud definitions: 'A' becomes 'Approved', 'D' becomes 'Denied', and 'I' remains 'I' (unformatted). This proves `fmtSearch='INSERT'` placed the 'FraudLib' at the start of the search path. For Step 2, the result set must also show the Fraud definitions. This proves that with `APPEND` (the default), the first library loaded ('FraudLib') is found first in the search path, and the conflicting format in the second library is ignored.