SAS MDY( ) function is mainly used create a SAS date value out of a three separate arguments Month, Day and Year.
As we know, SAS internally stores date as numeric value. Hence its important to create that specific number representing the given date (e.g. 1 JAN 1960 is Stored as 0 hence 2 JAN 1960 will be 1 and so on)
MDY( ) helps to create a SAS date representing the given date interms of Month, Day and Year.
This has been demonstrated below;
1. SAS MDY( ) Function
SYNTAX: MDY (month, day, year );
MDY() function takes 3 arguments
If we see the code more closely;
In the first statement year value is given with 4 digits, hence refers to 2nd March 2010.
In case of second statement year value specified is 2 digits and as YEARCUTOFF option is set as 1920; ‘98’ refers to 1998 and hence the actual date is 2nd March 1998.
In the third statement, we can observe that we get ‘.’ Missing value, as we provide wrong value ‘13’ as month to the MDY function.
Further in the log one can observe following NOTES
NOTE: Invalid argument to function MDY at line 18 column 23.
dt_with_4digit=18323 dt_with_2digit=13940 dt_with_wrong_month=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
Each place is given by: (Number of times) at (Line):(Column).
1 at 18:23
It is interesting to note the difference between first and second print procedures;
First print procedure don’t have format statement; hence date values are represented as actual values as those stored internally.
In the second print procedure; as format statement is used dates are represented in DATE9 format while printing.