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

How can I reformat a date from mmmyy7. to yyyy only? The data set I’m working in has multiple years of data. I want to strip/trim the ddMMM from the YYYY, i.e. leaving on the YYYY.

Message was edited by: Woody Sutton

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Actually with SAS dates I wouldn't change any values unless you want to add a new variable to a data set. Most analysis functions will use a formatted value and in your case that format would be YEAR4. when you need it. If you modify the date value I would bet that in short order someone will want quarterly or monthly summaries. Which with the original date value means you likely only have to change ther format to one appropriate. You don't even have to make the format change permanent, use at run time. However Proc Datasets will let you change change the default format by code or open the dataset in the SAS explorer in column view, click on the variable and type the desired format in the format box.

To build a new variable: Year=year(datevalue);

View solution in original post

4 REPLIES 4
Ksharp
Super User
data x;
 x='01jan2012'd;
 format x year4.;
 run;


Xia Keshan

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Or:

data x;

     x='01jan2012'd;

     y=year(x);

run;

ballardw
Super User

Actually with SAS dates I wouldn't change any values unless you want to add a new variable to a data set. Most analysis functions will use a formatted value and in your case that format would be YEAR4. when you need it. If you modify the date value I would bet that in short order someone will want quarterly or monthly summaries. Which with the original date value means you likely only have to change ther format to one appropriate. You don't even have to make the format change permanent, use at run time. However Proc Datasets will let you change change the default format by code or open the dataset in the SAS explorer in column view, click on the variable and type the desired format in the format box.

To build a new variable: Year=year(datevalue);

Woody_UNCW
Calcite | Level 5

thank you all for your help. i was successful in formatting 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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2095 views
  • 6 likes
  • 4 in conversation