Help using Base SAS procedures

How to display the current year in character data type

Reply
N/A
Posts: 0

How to display the current year in character data type

Hi,

I have encountered a problem in sas data integration studio which has been bugging me for some time.

I have a column called year which is a derived dated field that shows the current year.

Then i encountered a strange thing

if my column is a numeric data type and i do this -> YEAR(Date()) -> I get 2009

if my column is a character data type and i do this -> PUT(YEAR(Date(), year4.) -> I get 1965

It's so strange, so I like to find out how can I displayed 2009 in character data type?

Thanks.

Yours Sincerely,
helphelp
Occasional Contributor LOK
Occasional Contributor
Posts: 11

Re: How to display the current year in character data type

Posted in reply to deleted_user
Hi,

Try This

in place of
PUT(YEAR(Date(), year4.)

keep
put(year(date),4.);
SAS Employee
Posts: 174

Re: How to display the current year in character data type

Posted in reply to deleted_user
It's not strange

YEAR(Date()) will return 2009 as you write

But PUT(YEAR(Date()), year4.)

is the same as

PUT(2009,year4.)

Remember that year4. will display the year that is 2009 DAYS since 1960 - and 1965 is 2009 DAYS since 1960.

Just use PUT(date(), year4.)
Occasional Contributor LOK
Occasional Contributor
Posts: 11

Re: How to display the current year in character data type

Posted in reply to deleted_user
Hi,
you cen use any one of the following

PUT(YEAR(DATE), 4.)

PUT(DATE, YEAR4.)
N/A
Posts: 0

Re: How to display the current year in character data type

Posted in reply to deleted_user
Hi,

Thanks for the people out there that is helping me

one last clarification

PUT(YEAR(Date()) , year4.) return '1965'

PUT(YEAR(Date()), 4.) return '2009'

are there actually equivalent?

Thanks

Yours Sincerely,
helphelp
Super Contributor
Super Contributor
Posts: 3,174

Re: How to display the current year in character data type

Posted in reply to deleted_user
They are not equivalent. The YEARw. (you used YEAR4.) format takes a SAS DATE variable and displays the year-portion. So, your code took the SAS numeric variable value 2009 (which represents the date 19MAY1965) and displayed only the year for that date.

Also, the YEAR() function takes a SAS DATE numeric variable and extracts the year-portion, assigning the value to a variable, as you used it.

The link below provides useful SAS Base DOC reference on this topic.


Scott Barry
SBBWorks, Inc.

Dates, Times, and Intervals
About SAS Date, Time, and Datetime Values
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm
Ask a Question
Discussion stats
  • 5 replies
  • 589 views
  • 0 likes
  • 4 in conversation