Hi,
I have issue with this....different company is having same id ....in that scenario i'm getting error.
how can i handle that one.
my code:
data bbb;
set aaa end=eof;
by company;
if not eof then
set aaa(firstobs=2 keep=date rename=date=date_after);
if first.company and last.company then date_after=date;
if last.company then date_after=.;
run;
example scenario:
company id date
xyz 123 02/11/2009
xyz 123 03/11/2009
abc 123 05/11/2009
output should be:
company id date next_date
xyz 123 02/11/2009 03/11/2009
xyz 123 03/11/2009 .
abc 123 05/11/2009 .
current output:
company id date next_date
xyz 123 02/11/2009 03/11/2009
xyz 123 03/11/2009 05/11/2009
abc 123 05/11/2009 .
Thanks,
rk
It looks like you've already been offered a number of ways to do this but, since you asked, how about:
data aaa;
input company $ id date mmddyy8.;
format date date9.;
cards;
xyz 123 02/11/2009
xyz 123 03/11/2009
abc 123 05/11/2009
bbb 124 01/12/2010
bbb 124 01/13/2010
bbb 124 01/14/2010
bbb 124 01/15/2010
bbb 124 01/16/2010
bbb 124 01/13/2010
bbb 124 01/14/2010
;
proc sort data=aaa;
by company id descending date;
run;
data bbb (drop=date_after);
set aaa;
by company id;
retain date_after;
format next_date date9.;
if first.id then call missing(next_date);
else next_date=date_after;;
date_after=date;
run;
proc sort data=bbb;
by company id date;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.