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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2004 views
  • 4 likes
  • 4 in conversation