- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would like to extract the only year from the date as a new variable how do I write the program?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It depends, but usually you would use a data step and the YEAR() function for starters.
You can run the example below.
data year_demo;
set sashelp.stocks;
year = year(date);
run;
@Hope18 wrote:
I would like to extract the only year from the date as a new variable how do I write the program?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It depends, but usually you would use a data step and the YEAR() function for starters.
You can run the example below.
data year_demo;
set sashelp.stocks;
year = year(date);
run;
@Hope18 wrote:
I would like to extract the only year from the date as a new variable how do I write the program?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you guys this was helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It depends on how your date is stored - for example if it's a SAS datetime you can use the date part function http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p0rttbu7w62xgzn1damccyuwpld8.htm&... or if it's a character then the substr function http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n0n08xougp40i5n1xw7njpcy0a2b.htm&...
If you tell us how it's stored we can give you a concrete example.