In order to Extract day of month, day of year and day of week from date in SAS using intnx() Function. Let’s see an example on how to get day of month from date in SAS. Day of the year from date in SAS. Day of week from date in SAS (week number from date in SAS).
- Get day of month from date in SAS
- Get day of year from date in SAS
- Get day of week from date in SAS
So we will be using EMP_DET Table in our example
Get day of year in SAS:
To Get day of year from date in SAS we will be using INTNX() Function. First we will find SAS date for start of the year using INTNX() function, then we will subtract it from birthday column then + 1 will give you day of the year.
/* day of year */ data emp_det1; set emp_det; dayofyear= Birthday - intnx('year', Birthday, 0)+1; run;
So the resultant table will be
Get day of month in SAS:
To Get day of month from date in SAS we will be using INTNX() Function. First we will find SAS date for start of the month using INTNX() function, then we will subtract it from birthday column then + 1 will give you day of the month.
/* day of month*/ data emp_det1; set emp_det; dayofmonth= Birthday - intnx('month', Birthday, 0)+1; run;
So the resultant table will be
Get day of week from date in SAS: Method 1
To Get day of week from date in SAS we will be using weekday() Function.
/* day of week - method 1 */ data emp_det1; set emp_det; dayofweek= weekday(Birthday); run;
weekday() function returns week number from date with : 1=Sunday, 2=Monday,…, 7=saturday.
Get day of week in SAS: Method 2
Day of week from date is also accomplished using INTNX() Function as shown below
/*day of week - method 2 */ data emp_det1; set emp_det; dayofweek=Birthday - intnx('week', Birthday, 0)+1; run;
nth day of week starting from Sunday. 1=Sunday, 2=Monday,…, 7=saturday