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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

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