- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
I am trying to getting month and year from a datetime. field. While I manage to get May2017 from '02MAY17:07:57:59', I need it in the format 052017 i.e month expressed in digits. Can someone please guide how I can achieve it? Please find below the code I tried.
DATA date_constants;
datetime = '02MAY17:07:57:59'dt; /* This is a datetime constant */
run;
TITLE “Unformatted Constants”;
PROC PRINT DATA=date_constants;
VAR datetime;
run;
TITLE “Formatted Constants”;
PROC PRINT DATA=date_constants;
VAR datetime;
FORMAT datetime datetime.;
run;
data date_tril;
set date_constants;
serve = datepart(datetime);
format serve monyy7.;
PROC PRINT DATA=date_tril;
run;
Thanks,
Akhilesh Joshi
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To be clear, you're not trying to get the month and year from the field. You're extracting the date and then formatting it. I think what you want is mmyyn6. for your format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To be clear, you're not trying to get the month and year from the field. You're extracting the date and then formatting it. I think what you want is mmyyn6. for your format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Colin,
That format worked!
Thanks much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi:
Once you use the DATEPART function, then it should only be a matter of picking the right format, as shown below. As you can see the same date is formatted multiple ways using different formats.
cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Awesome ,Cynthia! Thanks a lot!