DATA Step, Macro, Functions and more

Create Year Column

Accepted Solution Solved
Reply
Super Contributor
Posts: 497
Accepted Solution

Create Year Column

I am trying to save the numeric year as a column based off of a data column.

In a datastep I have

Year = year(Project_Start);

Oddly the year returns blank.  In the log there is this line:

NOTE: Invalid argument to function YEAR(1772409600) at line 80 column 9.

 


Accepted Solutions
Solution
‎11-24-2015 11:10 AM
Super User
Posts: 19,822

Re: Create Year Column

Posted in reply to DavidPhillips2
Is project_start a datetime? If so, use the datepart function to take the date part first.

year=year(datepart(project_start));

View solution in original post


All Replies
Solution
‎11-24-2015 11:10 AM
Super User
Posts: 19,822

Re: Create Year Column

Posted in reply to DavidPhillips2
Is project_start a datetime? If so, use the datepart function to take the date part first.

year=year(datepart(project_start));
Respected Advisor
Posts: 3,156

Re: Create Year Column

[ Edited ]
Posted in reply to DavidPhillips2

Most likely you are dealing with a date-time value instead of date. Try this:

Year = year(datepart(Project_Start));

Or this:

Year=input(put(Project_Start,dtyear4.),4.);

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 182 views
  • 1 like
  • 3 in conversation