BookmarkSubscribeRSS Feed
klj81
Fluorite | Level 6

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.

 

 

 

6 REPLIES 6
Reeza
Super User

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.

 

 

 


 

Barkat
Pyrite | Level 9

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

Spoiler
data have;
input ID $ StartDay StartMonth StartYear ;
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
;
ballardw
Super User

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.

Barkat
Pyrite | Level 9

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!

 

Barkat
Pyrite | Level 9
It worked. I had a mistake in my code for sample data (switch StartDay and StartMontn). That is why I got missing StartDate. Thanks so much!
Barkat
Pyrite | Level 9
Thanks for your advise. I will start a new question then.

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
  • 6 replies
  • 2472 views
  • 4 likes
  • 4 in conversation