?>
The `addFormat` action is a powerful tool within the `sessionProp` action set. It allows for the dynamic creation and addition of a new user-defined format to a specified format library within the current CAS session. This is particularly useful for creating custom data representations on-the-fly without needing to pre-define them in a SAS catalog. You can define simple value mappings or complex ranges, and even create picture formats for detailed numeric formatting. The created formats are immediately available for use in the session where they were defined.
| Parameter | Description |
|---|---|
| dataType | Indicates whether the value is of type DATE, TIME, or DATETIME. |
| defaultL | Specifies the default length of the format. |
| fill | Indicates the fill character for a PICTURE format. |
| fmtLibName | Specifies the name of the format library where the new format will be stored. |
| fmtName | Specifies the name for the new format. A character format name must start with a '$'. |
| fmtType | Indicates the type of format: PICTURE, INVALUE, or VALUE. |
| fuzz | Specifies a fuzz factor for matching numeric values to a range. Values within the fuzz factor of a range endpoint are included in the range. |
| locale | Specifies the locale to be used in the format name's locale prefix, enabling culture-specific formatting. |
| maxL | Specifies the maximum length for the format, in bytes. |
| minL | Specifies the minimum length for the format, in bytes. |
| mult | Indicates a multiplier for a PICTURE format, used instead of computing from decimal points. |
| multiLabel | If set to True, allows multiple labels to be specified for a single internal value. |
| noedit | Indicates a non-picture label for a PICTURE format. |
| notSorted | If set to True, values or ranges are stored in the order they are defined, rather than being sorted. |
| prefix | Indicates prefix characters for a PICTURE format. |
| ranges | Specifies a list of value-to-label or range-to-label mappings. For example, `{"1='Low'", "2-5='Medium'", "6-10='High'"}`. |
| replace | If set to True, an existing format of the same name will be overwritten with the new definition. |
First, we create a format library named 'myFmtLib' to store our custom formats. Then, we load a simple dataset into a CAS table named 'ProductSales'. This table contains product IDs and their corresponding sales figures, which we will use to apply our custom formats.
proc cas; session casauto; action sessionProp.addFmtLib / fmtLibName='myFmtLib', replace=true; run; data casuser.ProductSales; infile datalines; input ProductID Sales; datalines; 1 150 2 2500 3 800 4 5500 5 450 ; run; quit;
This example demonstrates how to create a basic numeric format named 'SalesFormat'. This format categorizes sales figures into 'Low', 'Medium', and 'High'. We add this format to our 'myFmtLib' library.
| 1 | PROC CAS; ACTION sessionProp.addFormat / fmtLibName='myFmtLib' fmtName='SalesFormat' ranges={'1-1000=Low', '1001-5000=Medium', '5001-high=High'}; RUN; QUIT; |
This example creates a character format '$ProdName' in the 'myFmtLib' library. It maps product IDs to their names. The `replace=true` option ensures that if a format with the same name already exists, it will be overwritten. This is useful for updating format definitions during development.
| 1 | PROC CAS; ACTION sessionProp.addFormat / fmtLibName='myFmtLib' fmtName='$ProdName' ranges={'1=Laptop', '2=Desktop', '3=Tablet', '4=Monitor', 'other=Unknown'} replace=true; RUN; QUIT; |
This example shows how to create a sophisticated numeric picture format for currency, specific to the German (Germany) locale. It defines a format named 'EUROFMT' that includes a Euro symbol prefix, uses a dot as the thousands separator, and a comma for the decimal point, which is standard for this locale. The `locale='de_DE'` parameter is key to this functionality.
| 1 | PROC CAS; ACTION sessionProp.addFormat / fmtLibName='myFmtLib' fmtName='EUROFMT' fmtType='PICTURE' defaultL=16 ranges={'low-high=000.000,00'} prefix={'€ '} locale='de_DE'; RUN; QUIT; |
A financial institution needs to classify its customers into risk categories based on their credit score. This allows for tailored product offerings and risk management. The for...
A global e-commerce company needs to generate financial reports where sales figures are displayed in the correct, locale-specific currency format. This involves using different ...
In a manufacturing setting, IoT sensors monitor machine operating temperatures. Due to minor sensor inaccuracies, readings can be very close to a threshold. We need to classify ...