Hi,
I have a dataset
DOB (character)
07/1980
03/1978
10/1982
I want this to change to numeric. And a separate month and year column added.
DOB(numeric) Month Year
07/1980 July 1980
03/1978 March 1978
10/1982 October 1982
thanks in advance
One way:
data have; input dob $; datalines; 07/1980 03/1978 10/1982 ; data want; set have; dobnum = input(dob,anydtdte.); format dobnum mmyys7.; /*redundant*/ month = put(dobnum,monname. -L); year = year(dobnum); run;
The Input creates a date value using a very flexible approach for many date layouts. In this case it will assume that the day of the month is 1.
The Month and Year are redundant because you can get them easily from the Dobnum variable by applying a format if needed. The -L in the Put is the left justify the value so that there aren't any leading spaces in the month text.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.