- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How would you suggest combining birthmonth and birthyear into birth date?
Thank you!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Birth_Date = MDY(birthmonth, 15, birthyear);
Duration = interview_date - birth_date;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What are these two fields (birthmonth and birthyear) stored as? January and 1990? Are they strings?
You really need to help yourself by providing all the information when asking a question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So for participant 45, their birthdate is January 1978. When I use birth_date=MDY (birthmonth, 15, birthyear) I end up with a birthdate of 6589.
I'm sure its something simple I'm missing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
"January 1978" is not an exact date. @Reeza used 15 as the day of the month in the mdy() function to create such an exact date.
The mdy() function creates a SAS date value which is the count of days since 1/1/1960. To print such a count in a human readable form apply a format to the variable like: format Birth_Date date9.;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Add the following line to have them show as a SAS date.
format birth_date date9.;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Nothing is missing, really. SAS date is the number of days since the beginning of 1960, which is 6589 for 1978-01-15. Since the SAS date is merely a number, SAS prints it by default using the BEST12. format, and so it is displayed as 6589. If you want to see it as a formatted date, you need to apply one of (a great variety of) date formats to your birth_date variable. For example, run this:
data _null_ ;
retain birthmonth 1 birthday 15 birthyear 1978 ;
birth_date = MDY (birthmonth, birthday, birthyear) ;
put birth_date=best12. birth_date=yymmdd10. ;
run ;
Result in the SAS log:
birth_date=6589 birth_date=1978-01-15
If you're creating a data set with the birth_date variable and want it to appear formatted in a viewer or other kind of output medium, assign the format to the variable:
data want ; retain birthmonth 1 birthday 15 birthyear 1978 ; birth_date = MDY (birthmonth, birthday, birthyear) ; format birth_date yymmdd10. ; run ;
I strongly recommend that a format where year, month, day are listed in this sequence be used, without exception, to preserve sanity when browsing data sorted by date.
Kind regards
Paul D.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@hashman wrote:
I strongly recommend that a format where year, month, day are listed in this sequence be used, without exception, to preserve sanity when browsing data sorted by date.
Absolutely concur with this. There is an international standard for writing out dates and times (ISO 8601), and the SAS formats YYMMDDD10. and E8601DA10. both display a date according to this standard, in a nice human-readable way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content