BookmarkSubscribeRSS Feed
Mdormond
Calcite | Level 5

I have a study that has a starting point of 1998. I also have the variable "event date" which consists of a number either +/- the starting point. I would like to convert this number into "year of event" to determine in what year after 1998 the event occurred.  Is there a way to easily code this?

3 REPLIES 3
PGStats
Opal | Level 21

Use SAS date functions, shift the starting point date by event date days and get what year that is :

starting_point = '25OCT1998'd;

year = year(intnx("DAY", starting_point, event_date));

PG

PG
Chrishi
Calcite | Level 5

data want;

set have;

event=event_date+starting_point;

year = year(event);

run;

hope this code will solve your issue.

Sudeer.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Whist the above two answers are completely correct, I am questioning what the question is.  You state you have a starting point of 1998, which is fine.  It is this event date variable which I am not sure on.  Does this reference a time interval from the year or something else.  I.e. does it contain days since 1998, years since then, quarters, or is it something completely adhoc such as category 2 indicates 5 years.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 442 views
  • 0 likes
  • 4 in conversation