Dear All,
I need to convert the date format variable in to month-year format.
04JAN18:10:22:00(type=date)---->JAN18(type=date)
Thanks,
Chithra
Type=date - you don't seem to understand what a date or time actually is. Dates are stored as the number of days since a certain timepoint, so all dates are stored this way. Same with times, number of seconds since midnight. Both are numbers, which can be formatted in different ways. So if your Created variable is indeed numeric then you should be able to do:
data want; set have; new_created=datepart(created); format new_created monyy5.; run;
Type=date - you don't seem to understand what a date or time actually is. Dates are stored as the number of days since a certain timepoint, so all dates are stored this way. Same with times, number of seconds since midnight. Both are numbers, which can be formatted in different ways. So if your Created variable is indeed numeric then you should be able to do:
data want; set have; new_created=datepart(created); format new_created monyy5.; run;
Thanks..It works.
Thanks for the explanation also
04JAN18:10:22:00 is not a date value, but a datetime value.
Try this
newvar = datepart(oldvar):
format newvar monyy5.;
Date variables are not stored in a formatted way. They are stored numerically as the number of days since 01JAN1960. Only when presenting them in a report or a table viewer a format is used. Conversion is not needed when you want to reconsider the presentation format of your variable. In your case the format MONYY5. would the appropriate one. MONYY7. would also print the century.
Formats are a fundamental concept in SAS. Have a look at the doc if you want to read up on how they are used in SAS.
Hope this helps,
-- Jan.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.