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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.