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
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);
data x; x='01jan2012'd; format x year4.; run;
Xia Keshan
Hi,
Or:
data x;
x='01jan2012'd;
y=year(x);
run;
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);
thank you all for your help. i was successful in formatting the data.
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!
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.