Hello, I am working with a date variable (type is double) in a large dataset. It is of uneven length with some values YYYYMMDD, some YYYYMM and some just YYYY. I want to generate a new variable and extract just the YYYY from this variable. How can I do this? I came across the substr command for string variables, so was thinking of converting this numeric double variable to string but still unable to figure it out. I basically want to save the first four digits of each value. Will appreciate the guidance. Thank you!
2004 |
20150623 |
20190802 |
2017 |
20140826 |
200402 |
20090519 |
20090415 |
20011011 |
200807 |
20171021 |
Comment