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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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