Extract Week Number (week of year) and month number from date in SAS

In order to Extract week number (week of year) and month number from date in SAS we will using week() and month() Function. Week number from date in SAS is extracted using week() Function and month number from date in SAS is extracted using month() function.

  • Get week number from date in SAS or week of a year in SAS
  • Get month number from date in SAS

So we will be using EMP_DET Table in our example

Extract Week Number (week of year) and month number from date in SAS 1

 

 

Extract Week number from date (Get Week of Year) in SAS

To Get week number from date in SAS we will be using week() Function. week() function returns the week of the year from date in SAS

/* week number from date */ 

data emp_det1; 
set emp_det; 
weeknumber= week(Birthday); 
run;

Note: It returns 0 when the week is incomplete until the first Sunday is encountered.

Extract Week Number (week of year) and month number from date in SAS 2

 

 

Extract Month number from date in SAS

To Get month number from date in SAS we will be using month() Function. month() function returns the month of the year from date in SAS

/* month number from date */ 

data emp_det1; 
set emp_det; 
monthnumber = month(Birthday); 
run;

So the resultant dataframe will be

Extract Week Number (week of year) and month number from date in SAS 3