Posts

Showing posts with the label YYYY

How to extract year information from three formats of dates in a dataset? (IMPUTED Dates)

Image
The LINKEDIN SAS Professionals group had a question on How to extract year information from three formats of dates in a dataset? (IMPUTED Dates). There were a number of good suggestions submitted. Here is a summary of the suggestions: **************************************************************; *Method1: Using scan or substr with length functions; data temp; infile datalines; input date: $10. ; datalines; 1998 2008 01-1998 01-2008 01-01-1998 01-01-2008 ; run; data temp; set temp; if length (date) = 4 then year = input(substr (date, 1 , 4 ), best32 .); else if length (date) = 7 then year = input(substr (date, 4 , 4 ), best32 .); else if length (date) = 10 then year = input(substr (date, 7 , 4 ), best32 .); run ; *(or); data temp; set temp; if length (date) = 4 then year = input (date, best .); else if length (date) = 7 then year = input(scan (date, 2 , '-' ), best .); else if length (date) = 10 then year = input(scan (date, 3...