DATA Step, Macro, Functions and more

Create Year Column

Accepted Solution Solved
Reply
Super Contributor
Posts: 480
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: 17,836

Re: Create Year Column

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: 17,836

Re: Create Year Column

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,124

Re: Create Year Column

[ Edited ]

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.

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

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