?>Array ( [id] => 98 ) Complex Case: Locale-Specific Picture Format for Financial Reporting - WeAreCAS
sessionProp addFormat

Complex Case: Locale-Specific Picture Format for Financial Reporting

Scénario de test & Cas d'usage

Contexto empresarial

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 prefixes (€, $) and number formatting conventions (e.g., comma vs. period for decimal separators).
Preparación de datos

Creation of a sales dataset with transactions from Germany and the USA.

¡Copiado!
1DATA casuser.GlobalSales;
2 INFILE DATALINES truncover;
3 INPUT TransactionID $ Amount Country $;
4 DATALINES;
5TRN001 12500.75 DE
6TRN002 8345.50 US
7TRN003 999.99 DE
8TRN004 150100.00 US
9;
10RUN;

Étapes de réalisation

1
Create a format library named 'CurrencyFormats'.
¡Copiado!
1PROC CAS;
2 ACTION sessionProp.addFmtLib /
3 fmtLibName='CurrencyFormats',
4 replace=true;
5RUN;
6QUIT;
2
Create a German Euro picture format using locale 'de_DE', which uses a dot for thousands and a comma for decimals.
¡Copiado!
1PROC CAS;
2 ACTION sessionProp.addFormat /
3 fmtLibName='CurrencyFormats'
4 fmtName='EUROFMT'
5 fmtType='PICTURE'
6 defaultL=20
7 ranges={'low-high=000.000.000,00'}
8 prefix={'€ '}
9 locale='de_DE';
10RUN;
11QUIT;
3
Create a US Dollar picture format using locale 'en_US', with a standard dollar sign prefix.
¡Copiado!
1PROC CAS;
2 ACTION sessionProp.addFormat /
3 fmtLibName='CurrencyFormats'
4 fmtName='USDFMT'
5 fmtType='PICTURE'
6 defaultL=20
7 ranges={'low-high=0,000,000.00'}
8 prefix={'$'};
9RUN;
10QUIT;
4
Use a CAS data step to apply the correct format based on the 'Country' column and create a new formatted sales column.
¡Copiado!
1PROC CAS;
2 loadactionset 'datastep';
3 RUN;
4 datastep.runCode /
5 code='data casuser.FormattedSales; set casuser.GlobalSales; length FormattedAmount $20; if Country="DE" then FormattedAmount = put(Amount, EUROFMT.); else if Country="US" then FormattedAmount = put(Amount, USDFMT.); run;';
6RUN;
7 TABLE.fetch / TABLE='FormattedSales';
8RUN;
9QUIT;

Resultado esperado


The 'FormattedSales' table should contain a 'FormattedAmount' column. For German transactions, amounts should be like '€ 12.500,75'. For US transactions, they should be like '$150,100.00'. This validates the creation and application of locale-specific picture formats.