BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cherry
Obsidian | Level 7

hi i have a dataset which contains one variable date/

Variable - date

06/20/2010

06/16/2010

06/22/2010

06/20/2010

i want to replace the value of 06 ( month ) with 04 and 2010 ( year ) with 2011.

how can i achieve this?

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

If you only want to change certain dates, you could do it with something like:

data have;

  informat date mmddyy10.;

  format date mmddyy10.;

  input date;

  cards;

06/20/2010

06/16/2010

06/22/2010

06/20/2010

;

data want;

  set have;

  if month(date) eq 6 then date=

    mdy(4,day(date),year(date));

  if year(date) eq 2010 then date=

    mdy(month(date),day(date),2011);

run;

View solution in original post

3 REPLIES 3
mojerry2
Fluorite | Level 6

I suppose your date is a valid sas date. This value is a number into your dataset.

the intnx function is the best way to increase or decrease your date values.

new_month = intnx('month',date,1); /* this adds one month to your date */

new_month2 = intnx('year',new_month,1); /* this adds one year to your date */

if it's text you can use substring and convert your date to a sas date using the mdy(month,day,year) function.

art297
Opal | Level 21

If you only want to change certain dates, you could do it with something like:

data have;

  informat date mmddyy10.;

  format date mmddyy10.;

  input date;

  cards;

06/20/2010

06/16/2010

06/22/2010

06/20/2010

;

data want;

  set have;

  if month(date) eq 6 then date=

    mdy(4,day(date),year(date));

  if year(date) eq 2010 then date=

    mdy(month(date),day(date),2011);

run;

Cherry
Obsidian | Level 7

Hi Sir,

Thank you so much for your time. This is really useful to me.

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
  • 7874 views
  • 1 like
  • 3 in conversation