DATA Step, Macro, Functions and more

Using PROC SQL and need to do YEAR(DATE) AS BID_YEAR

Accepted Solution Solved
Reply
Contributor
Posts: 35
Accepted Solution

Using PROC SQL and need to do YEAR(DATE) AS BID_YEAR

I am using EG and PROC SQL to pull the YEAR from a Date field. 

 

So I used:

 

YEAR(Field_Name) AS BID_YEAR

 

did the same thing for MONTH, however I am getting this error:

 

NOTE: Invalid argument to function YEAR. Missing values may be generated.

NOTE: Invalid argument to function MONTH. Missing values may be generated.

 

So, how does this need to be written?

 

 

 


Accepted Solutions
Solution
‎11-21-2016 12:42 PM
Respected Advisor
Posts: 4,651

Re: Using PROC SQL and need to do YEAR(DATE) AS BID_YEAR

Your date variable is probably a SAS datetime, and not a SAS date. Try YEAR(DATEPART(field_name)) as BID_YEAR;

PG

View solution in original post


All Replies
Valued Guide
Posts: 797

Re: Using PROC SQL and need to do YEAR(DATE) AS BID_YEAR

Are you sure that the field has no missing values?
Contributor
Posts: 35

Re: Using PROC SQL and need to do YEAR(DATE) AS BID_YEAR

Yes, it is coming from an access db, and I checked, it is a date field and there are dates in the tbl.  I even went back to make sure I was using the correct syntax and I am

 

MONTH(BD.BID_DATE) AS BID_MONTH

 

So I am at a loss...

Solution
‎11-21-2016 12:42 PM
Respected Advisor
Posts: 4,651

Re: Using PROC SQL and need to do YEAR(DATE) AS BID_YEAR

Your date variable is probably a SAS datetime, and not a SAS date. Try YEAR(DATEPART(field_name)) as BID_YEAR;

PG
Contributor
Posts: 35

Re: Using PROC SQL and need to do YEAR(DATE) AS BID_YEAR

As I was thinking about it, I had to do that for another calculation, so that was the issue!  Thank you!!

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 193 views
  • 0 likes
  • 3 in conversation