BookmarkSubscribeRSS Feed
manya92
Fluorite | Level 6

does this code mean ?

death_date = mdy(substr(DateOfDeath,6,2),'15',substr(DateOfDeath,1,4)) ;

 

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Kurt_Bremser
Super User

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. 

ballardw
Super User

 

 

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

Reeza
Super User
I would also be double checking it. You have month at character 6 and year at character 1
YYYYXXMM -> it's almost unheard of to use this type of date formatting. It's usually YYYYMMDD.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 771 views
  • 0 likes
  • 5 in conversation