BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

Using SAS 9.4

 

I am trying to split '01/01/2019' in mmddyy10. format to get only the year 2019 from the date.

 

I have ran this code to try and pull the year out but it is not working. Any help would be appreciated. Thank you

 

DATA want;
SET have;

YEAR_OF_BIRTH  = SUBSTRN (DOB, 7, 10);

run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@GS2 wrote:

Using SAS 9.4

 

I am trying to split '01/01/2019' in mmddyy10. format to get only the year 2019 from the date.

 

I have ran this code to try and pull the year out but it is not working. Any help would be appreciated. Thank you

 


For future reference, it's never enough to tell us that its not working. We need more information than "it's not working". We would need to see the log (not just the error messages, but the log for the entire DATA step) and/or other indications of it not working.

 

I'm guessing that in this case, it seems as if your date is a numeric SAS date value, and so SUBSTRN will not work on numbers, it only works on characters. So the year function ought to do what you want, if it is truly a SAS date value.

 

what_year = year(date);

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

@GS2 wrote:

Using SAS 9.4

 

I am trying to split '01/01/2019' in mmddyy10. format to get only the year 2019 from the date.

 

I have ran this code to try and pull the year out but it is not working. Any help would be appreciated. Thank you

 


For future reference, it's never enough to tell us that its not working. We need more information than "it's not working". We would need to see the log (not just the error messages, but the log for the entire DATA step) and/or other indications of it not working.

 

I'm guessing that in this case, it seems as if your date is a numeric SAS date value, and so SUBSTRN will not work on numbers, it only works on characters. So the year function ought to do what you want, if it is truly a SAS date value.

 

what_year = year(date);

 

--
Paige Miller
Astounding
PROC Star

Just in case your variable is actually a character variable, you could use:

 

year_of_birth = scan(dob, -1, '/') ;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 508 views
  • 0 likes
  • 3 in conversation