Scénario de test & Cas d'usage
Execution of SAS FCMP functions within the CAS environment.
Discover all actions of fcmpactCreate a sample table of customer purchases with varying loyalty statuses and amounts to test the different discount tiers.
| 1 | DATA casuser.customer_purchases(promote=yes); |
| 2 | LENGTH customerId $ 10 loyaltyStatus $ 8; |
| 3 | INFILE DATALINES dsd; |
| 4 | INPUT customerId $ loyaltyStatus $ purchaseAmount; |
| 5 | DATALINES; |
| 6 | CUST001,Gold,550 |
| 7 | CUST002,Silver,120 |
| 8 | CUST003,Bronze,75 |
| 9 | CUST004,Gold,80 |
| 10 | CUST005,Silver,250 |
| 11 | ; |
| 12 | RUN; |
| 1 | PROC CAS; |
| 2 | SESSION casauto; |
| 3 | fcmpact.addRoutines |
| 4 | routineCode={ 'function calculate_discount(status $, amount); |
| 5 | length calculated_discount 8; |
| 6 | if upcase(status) = "GOLD" and amount > 500 then calculated_discount = amount * 0.20; |
| 7 | else if upcase(status) = "GOLD" then calculated_discount = amount * 0.15; |
| 8 | else if upcase(status) = "SILVER" then calculated_discount = amount * 0.10; |
| 9 | else calculated_discount = amount * 0.05; |
| 10 | return(calculated_discount); |
| 11 | endsub;' }, |
| 12 | package='marketing.discounts', |
| 13 | funcTable={name='marketing_funcs', caslib='casuser', replace=true}; |
| 14 | RUN; |
| 1 | PROC CAS; |
| 2 | SESSION casauto; |
| 3 | DATA casuser.customer_offers(promote=yes); |
| 4 | method RUN(); |
| 5 | SET casuser.customer_purchases; |
| 6 | discount = calculate_discount(loyaltyStatus, purchaseAmount); |
| 7 | END; |
| 8 | dcl package fcmpact('marketing.discounts') p; |
| 9 | RUN; |
| 10 | |
| 11 | TABLE.fetch / TABLE={caslib='casuser', name='customer_offers'}; |
| 12 | RUN; |
The 'marketing_funcs' table is created in the 'casuser' caslib. The subsequent DATA step successfully uses the 'calculate_discount' function. The final 'customer_offers' table contains a 'discount' column with correctly calculated values: 110 for CUST001, 12 for CUST002, 3.75 for CUST003, 12 for CUST004, and 25 for CUST005.