Published on :

Date Manipulation with INTNX

This code is also available in: Español Français
Awaiting validation
The script generates a working table 'FUNCAO_INTNX' from the system table 'SASHELP.SHOES'. It assigns a specific reference date ('DT_INI') to each geographical region via a series of conditions. Then, the 'INTNX' function is used to calculate a final date ('dt_final') by adding 2 months to the initial date and positioning the result at the end of the month. A final SQL query lists the distinct regions available.
Data Analysis

Type : SASHELP


Exclusive use of the SASHELP.SHOES example table.

1 Code Block
DATA STEP Data
Explanation :
Creation of the FUNCAO_INTNX table. Initialization of the DT_INI variable via the MDY function based on the region, then calculation of dt_final by advancing 2 'month' intervals and aligning to the end of the month ('end').
Copied!
1DATA FUNCAO_INTNX;
2 SET SASHELP.SHOES;
3 IF REGION = "Africa" THEN DT_INI = MDY(01,01,2021);
4 IF REGION = "Asia" THEN DT_INI = MDY(02,01,2021);
5 IF REGION = "Canada" THEN DT_INI = MDY(03,01,2021);
6 IF REGION = "Central America/Caribbean" THEN DT_INI = MDY(04,01,2021);
7 IF REGION = "Eastern Europe" THEN DT_INI = MDY(05,01,2021);
8 IF REGION = "Middle East" THEN DT_INI = MDY(06,01,2021);
9 IF REGION = "Pacific" THEN DT_INI = MDY(07,01,2021);
10 IF REGION = "South America" THEN DT_INI = MDY(08,01,2021);
11 IF REGION = "United States" THEN DT_INI = MDY(09,01,2021);
12 IF REGION = "Western Europe" THEN DT_INI = MDY(10,01,2021);
13
14 dt_final = intnx("month",DT_INI,2,"end");
15
16 FORMAT dt_ini dt_final date9.;
17 
18RUN;
2 Code Block
PROC SQL
Explanation :
Extraction and display of the list of unique values for the REGION column from the source table.
Copied!
1PROC SQL;
2 SELECT DISTINCT REGION FROM SASHELP.SHOES;
3 
4QUIT;
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.