BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chithra
Quartz | Level 8

Dear All,

 

I  need to convert the date format variable in to month-year format.

 

04JAN18:10:22:00(type=date)---->JAN18(type=date)

 

date_format.PNG

 

Thanks,

Chithra

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
chithra
Quartz | Level 8

Thanks..It works.

Thanks for the explanation also

jklaverstijn
Rhodochrosite | Level 12

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 15191 views
  • 2 likes
  • 4 in conversation