BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

I need to get the complete aedate from the partial available aedate. 

If year is same and month is greater than trtdate then add 01 as day to aedate

If year is same and month is less than trtdate then add 15 as day to aedate

If year is and month is same than  aedate=trtdate

if year is greater than year of trtdate then add 01 as day to aedate

 

Please help. Thank you

 

output needed;

id    aedate         trtdate
1     2016-11-01   09JUL2016
2    2016-06-15    17JUL2016
3    2016-07-17    17JUL2016
4    2017-01 -01    25NOV2016
;

 

 

data one;
input id aedate $ trtdate date9.;
datalines;
1 2016-11 09JUL2016
2 2016-06 17JUL2016
3 2016-07 17JUL2016
4 2017-01 25NOV2016
;

 

1 REPLY 1
nehalsanghvi
Pyrite | Level 9

Try this code. It works for the scenarios where year is greater or equal to trtdate year, but you have not specified what should happen if aedate year is less than trtdate year:

 

data one;
input id aedate $ trtdate date9.;
format trtdate date9.;
datalines;
1 2016-11 09JUL2016
2 2016-06 17JUL2016
3 2016-07 17JUL2016
4 2017-01 25NOV2016
;

data two;
set one;
format aedaten yymmdd10.;
aedaten = mdy(substr(aedate,6),01,substr(aedate,1,4));  /* create a date variable with 01 as the default day */
if year(aedaten)=year(trtdate) then do;
	if month(aedaten)<month(trtdate) then aedaten=aedaten+14;
	if month(aedaten)=month(trtdate) then aedaten=aedaten+16;
end;
run;

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
  • 1 reply
  • 1087 views
  • 1 like
  • 2 in conversation