BookmarkSubscribeRSS Feed
bhca60
Quartz | Level 8

How would I convert date from:

11OCT1936 to 10/11/1936  OR  to 10-11-1936?

 

 

 

2 REPLIES 2
ballardw
Super User

What is the current format of the variable? If it is DATE9. then you only need to change the format.

10/11/1936 would be mmddyy10.

10-11-1936 would be mmddyyd10.

 

If the value is character, i.e. a format like $9. , you would likely be better off by creating a new variable as a date value with code like

Newdate= input(date,date9.);

and assign a desired format.

 

If you haven't work much with dates the ability to create different summaries just by changing the format is a very powerful tool. Use a YEAR format and the summary using that date would summarize by year.

For example this uses a SAS supplied set you can test code with that summarizes by calendar year getting the lowest Low price, the maximum high price and the total sales volume from the dates in the data:

Proc tabulate data=sashelp.stocks;
   class stock  date;
   format date year4.;
   var high low volume;
   table stock*date,
         low*min='' high*max='' volume*sum=' '
   ;
run;

Changing the format from Year4 to YYQ6 creates calendar quarter summaries. Using MONNAME. will create month summaries across the years, i.e. January for all the years in the data.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 716 views
  • 2 likes
  • 3 in conversation