Published on :

Date calculations and late payment detection

This code is also available in: Deutsch Español Français
Awaiting validation
The script consists of three main blocks. The first block calculates the duration (days, business days, weeks, months) between the current date and a predefined holiday date, storing the results in a CAS table. The second block generates fictitious payment information, including a customer ID, a due date, and a payment receipt date, then saves them to another CAS table. The third block uses PROC PRINT to display records of customers whose payment was received more than 10 business days after the due date.
Data Analysis

Type : CREATION_INTERNE


All data processed and generated by this script is created internally. The first table is built from internal SAS functions (TODAY()) and literal dates. The second table is randomly generated using the RAND() function. No external data or SASHELP library is used as a primary source.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block initializes a CAS session and creates the 'casuser.tidTillSemestern' table. It calculates the difference between the current date (IDAG) and a semester start date (STARTSEM) using the INTCK function. Calculations are performed in days (DAGARTILLSEM), business days (VECKODAGARTILLSEM), weeks (VECKORTILLSEM), and months (MANADERTILLSEM), with the 'c' option for continuous counting for weeks and months. Dates are formatted as DDMMYYYY.
Copied!
1cas;
2 
3DATA casuser.tidTillSemestern;
4 idag = today();
5 startSem = '15jun2023'd;
6 dagarTillSem = intck('day', idag, startSem);
7 veckodagarTillSem = intck('weekday', idag, startSem);
8 veckorTillSem = intck('week', idag, startSem, 'c');
9 manaderTillSem = intck('month', idag, startSem, 'c');
10 FORMAT idag startSem yymmdd10.;
11RUN;
2 Code Block
DATA STEP Data
Explanation :
This DATA STEP block creates the 'casuser.betalningsInformation' table by generating 20 fictitious data records. For each 'kundID' (customer ID), it assigns a random 'forfallodatum' (due date) in March 2023 and a 'betalningInkommen' (payment receipt date) which is the due date plus or minus a random number of days (between -5 and 20). Dates are also formatted as DDMMYYYY.
Copied!
1/*skapa data*/
2DATA casuser.betalningsInformation;
3 DO kundID = 1 to 20;
4 forfallodatum = rand('integer', '01mar2023'd, '31mar2023'd);
5 betalningInkommen = forfallodatum + rand('integer', -5, 20);
6 OUTPUT;
7 END;
8 FORMAT forfallodatum betalningInkommen yymmdd10.;
9RUN;
3 Code Block
PROC PRINT
Explanation :
This block uses PROC PRINT to display a selection of records from the 'casuser.betalningsInformation' table. The WHERE clause filters records to include only customers whose difference between the due date and the payment receipt date, calculated in business days ('weekday') by the INTCK function, is greater than 10. This identifies customers with significant payment delays. The ID statement specifies that the KUNDID variable should be used as an identifier in the report.
Copied!
1/*Kunder som är mer än 10 veckodagar sena med sin betalning*/
2PROC PRINT DATA=casuser.betalningsInformation;
3 id kundID;
4 where intck('weekday', forfallodatum, betalningInkommen) > 10;
5RUN;
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.