BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
5 REPLIES 5
LOK
Calcite | Level 5 LOK
Calcite | Level 5
Hi,

Try This

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

keep
put(year(date),4.);
GertNissen
Barite | Level 11
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.)
LOK
Calcite | Level 5 LOK
Calcite | Level 5
Hi,
you cen use any one of the following

PUT(YEAR(DATE), 4.)

PUT(DATE, YEAR4.)
deleted_user
Not applicable
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 9760 views
  • 0 likes
  • 4 in conversation