Populate first and last day of month and Year SAS

In this tutorial we will Populate first and last day of month and Year SAS. In order to populate first and last date of a month in SAS we will be using INTNX function. This function is also used to populate first and last date of year in SAS.

Let’s see an Example for Each

  • Populate First date of a month in SAS
  • Populate Last date of a month in SAS
  • Populate First date of year in SAS
  • Populate Last Date of year in SAS

So we will be using EMP_DET Table in our example

Populate first and last day of month & Year SAS 1

 

 

INTNX –  Populate First date of a Month

In order to populate first date of a month in SAS we will be using INTNX() Function. It takes ‘month’ as argument along with ‘b’ which populates the first date of that particular month


data emp_det1; 
set emp_det; 
firstdate=intnx('month', Birthday, 0,'b'); 
format firstdate date9.; 
run;

So the resultant table will be

Populate first and last day of month & Year SAS 2

 

 

INTNX –  Populate Last date of a Month

In order to populate last date of a month in SAS we will be using INTNX() Function. It takes ‘month’ as argument along with ‘e’ which populates the last date of that particular month


data emp_det1; 
set emp_det; 
lastdate=intnx('month', Birthday, 0,'e'); 
format lastdate date9.; 
run; 

So the resultant table will be

Populate first and last day of month & Year SAS 3

 

 

INTNX – Populate First date of a year

In order to populate First date of year in SAS we will be using INTNX() Function. It takes ‘year’ as argument along with ‘b’ which populates the first date of that particular year


data emp_det1; 
set emp_det; 
firstdate=intnx('year', Birthday, 0,'b'); 
format firstdate date9.; 
run;

So the resultant table will be

Populate first and last day of month & Year SAS 4

 

INTNX –  Populate Last date of a Year

In order to populate last date of year in SAS we will be using INTNX() Function. It takes ‘year’ as argument along with ‘e’ which populates the last date of that particular year


data emp_det1; 
set emp_det; 
lastdate=intnx('year', Birthday, 0,'e'); 
format lastdate date9.; 
run; 


So the resultant table will be

Populate first and last day of month & Year SAS 5

 

                                                                                               

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.