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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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