Hello!
I have a very large data set where birthdays are separated into three columns.
I have Brthmn brthdt and brthyr.
I tried to use the MDY function to create the variable Birthdt which would include the month,date, and year.
The issue is that Brthmn is in the three letter abbreviation format (ex: 'Jan'), so I cannot use MDY because it is not a numeric variable.
Ultimately the date will need to be in the date9 format so if that could be done it would be great.. ALSO. There are some instances where the day is missing and I would need to assign a generic date to that person like date=01 for example. Any tips would be greatly appreciated.
Date = input(coalesce(day, 1)||mon||year, date9.);
Format date date9.;
Untested code due to lack of sample data.
@klj81 wrote:
Hello!
I have a very large data set where birthdays are separated into three columns.
I have Brthmn brthdt and brthyr.
I tried to use the MDY function to create the variable Birthdt which would include the month,date, and year.
The issue is that Brthmn is in the three letter abbreviation format (ex: 'Jan'), so I cannot use MDY because it is not a numeric variable.
Ultimately the date will need to be in the date9 format so if that could be done it would be great.. ALSO. There are some instances where the day is missing and I would need to assign a generic date to that person like date=01 for example. Any tips would be greatly appreciated.
I have the same question. I have mentioned a sample data, named have. I would like to combine StartDay, StartMonth, and StartYear to create a StartDate column.
Please help
If you have numeric values for month, day and year then use the MDY function. Then assign a format that humans can read in your preferred style.
data have; input ID $ StartDay StartMonth StartYear ; startdate = mdy(startmonth, startday,startyear); format startdate date9.; cards; 001 10 9 2022 002 4 3 2022 003 2 7 2022 004 7 17 2022 005 10 24 2022 006 11 14 2022 ;
BTW, it is preferred on this forum that you start a new question and reference an old one like this. The originator of a question has the ability to mark answers accepted. Also you never know when your question may become considerably more complex or different from the thread you add to.
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.
I used the following code. However the StartDate appears only in first three rows.
data want; set have;
startdate = mdy(startmonth, startday,startyear);
format startdate date9.;
run;
Thanks so much!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.