does this code mean ?
death_date = mdy(substr(DateOfDeath,6,2),'15',substr(DateOfDeath,1,4)) ;
Please try using even full sentences. What do you not understand, have you looked up the functions given in that line?
mdy() function accepts 3 numeric values representing month, day, year.
substr() function cuts out a certain amount of characters from X position in a string for Y number of characters.
This code is creating a death date variable with the day value 15 imputed. Do note its not a good idea to put a character - '15' - string in where a numeric is expected, this incurs implicit conversion.
It's sloppy programming. It uses strings where numeric values are expected, forcing SAS to do an automatic conversion, which is never good and often bad.
On the surface, this code makes a SAS date out of a string of 7 characters in the form 'yyyyXmm', where yyyy is a year and mm a month, and X any arbitrary character. Depending on the type and contents of DateOfDeath, this could work, or just get you missing values and lots of NOTEs in the log.
It would appear that someone has date values in a string and wants to set all of the same month and year to the 15th of the month. That is the purpose of the MDY function to take a month number (1 to 12) , day of month (1 to 31 BUT SAS will verify the number of days against the specific month) and year value and return a SAS data value.
I would guess that the data dateofdeath was in the form of something like YYYY/MM
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.