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

Hi,

I have following data

 

data have;
infile datalines missover; 
   input IDnumber @3 date  mmddyy10. index_date  mmddyy10.;
   datalines;  
1 4-7-2003 4-7-2003
1 4-7-2009 4-7-2009
1 4-7-2010 
1 4-7-2011 
1 4-7-2012 
1 4-7-2013 
1 4-7-2014 4-7-2014
1 4-7-2015 
1 4-7-2016 
1 4-7-2018 
2 4-7-2005 4-7-2005
2 4-7-2011 4-7-2011 
2 4-7-2012 
2 4-7-2013 
2 4-7-2014 
2 4-7-2015 
2 4-7-2016 4-7-2016
2 4-7-2017 
2 4-7-2018 
2 4-7-2019 
2 4-7-2020 
;       
run; 

What i need is to repeat the index date until the new index date. As following

 

 

data want;
infile datalines missover; 
   input IDnumber @3 date  mmddyy10. @12 index_date  mmddyy10.;
   datalines;  
1 4-7-2003  4-7-2003
1 4-7-2009  4-7-2009
1 4-7-2010  4-7-2009
1 4-7-2011  4-7-2009
1 4-7-2012 4-7-2009
1 4-7-2013 4-7-2009
1 4-7-2014 4-7-2014
1 4-7-2015 4-7-2014
1 4-7-2016 4-7-2014
1 4-7-2018 4-7-2014
2 4-7-2005 4-7-2005
2 4-7-2011 4-7-2011
2 4-7-2012 4-7-2011
2 4-7-2013 4-7-2011
2 4-7-2014 4-7-2011
2 4-7-2015 4-7-2011
2 4-7-2016 4-7-2016
2 4-7-2017  4-7-2016
2 4-7-2018  4-7-2016
2 4-7-2019  4-7-2016
2 4-7-2020  4-7-2016
;       
run; 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
infile datalines missover; 
   input IDnumber date  :mmddyy10. index_date :mmddyy10.;
   format date index_date mmddyy10.;
   datalines;  
1 4-7-2003 4-7-2003
1 4-7-2009 4-7-2009
1 4-7-2010 
1 4-7-2011 
1 4-7-2012 
1 4-7-2013 
1 4-7-2014 4-7-2014
1 4-7-2015 
1 4-7-2016 
1 4-7-2018 
2 4-7-2005 4-7-2005
2 4-7-2011 4-7-2011 
2 4-7-2012 
2 4-7-2013 
2 4-7-2014 
2 4-7-2015 
2 4-7-2016 4-7-2016
2 4-7-2017 
2 4-7-2018 
2 4-7-2019 
2 4-7-2020 
;       
run; 

data want;
 update have(obs=0) have;
 by IDnumber;
 output;
run;

proc print noobs;run;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

data have;
infile datalines missover; 
   input IDnumber date  :mmddyy10. index_date :mmddyy10.;
   format date index_date mmddyy10.;
   datalines;  
1 4-7-2003 4-7-2003
1 4-7-2009 4-7-2009
1 4-7-2010 
1 4-7-2011 
1 4-7-2012 
1 4-7-2013 
1 4-7-2014 4-7-2014
1 4-7-2015 
1 4-7-2016 
1 4-7-2018 
2 4-7-2005 4-7-2005
2 4-7-2011 4-7-2011 
2 4-7-2012 
2 4-7-2013 
2 4-7-2014 
2 4-7-2015 
2 4-7-2016 4-7-2016
2 4-7-2017 
2 4-7-2018 
2 4-7-2019 
2 4-7-2020 
;       
run; 

data want;
 update have(obs=0) have;
 by IDnumber;
 output;
run;

proc print noobs;run;
ifti_ch2002
Obsidian | Level 7
Thanks, we can even do with retain 🙂
Jagadishkatam
Amethyst | Level 16

please try the below code and check index_date2

 

data have;
infile datalines missover; 
   input IDnumber date :mmddyy10. index_date : mmddyy10.;
   datalines;  
1 4-7-2003 4-7-2003
1 4-7-2009 4-7-2009
1 4-7-2010 .
1 4-7-2011 .
1 4-7-2012 .
1 4-7-2013 .
1 4-7-2014 4-7-2014
1 4-7-2015 .
1 4-7-2016 .
1 4-7-2018 .
2 4-7-2005 4-7-2005
2 4-7-2011 4-7-2011 
2 4-7-2012 .
2 4-7-2013 .
2 4-7-2014 .
2 4-7-2015 .
2 4-7-2016 4-7-2016
2 4-7-2017 .
2 4-7-2018 .
2 4-7-2019 .
2 4-7-2020 .
;       
run; 

data want;
set have;
by IDnumber notsorted;
retain index_date2;
if first.IDnumber then index_date2=.;
if index_date ne . then index_date2=index_date;
format index_date index_date2 date date9.;
run;

 

Thanks,
Jag
PaigeMiller
Diamond | Level 26
data have;
infile datalines missover; 
   input IDnumber @3 date  mmddyy. @12 index_date  mmddyy10.;
   retain index_date1;
   if not missing(index_date) then index_date1=index_date;
   format date index_date1 mmddyy10.;
   datalines;  
1 4-7-2003 4-7-2003
1 4-7-2009 4-7-2009
1 4-7-2010 
1 4-7-2011 
1 4-7-2012 
1 4-7-2013 
1 4-7-2014 4-7-2014
1 4-7-2015 
1 4-7-2016 
1 4-7-2018 
2 4-7-2005 4-7-2005
2 4-7-2011 4-7-2011 
2 4-7-2012 
2 4-7-2013 
2 4-7-2014 
2 4-7-2015 
2 4-7-2016 4-7-2016
2 4-7-2017 
2 4-7-2018 
2 4-7-2019 
2 4-7-2020 
;       
run; 
--
Paige Miller
novinosrin
Tourmaline | Level 20

Boring afternoon and so just for some fun

 

data have;
infile datalines missover; 
   input IDnumber date  :mmddyy10. index_date :mmddyy10.;
   format date index_date mmddyy10.;
   datalines;  
1 4-7-2003 4-7-2003
1 4-7-2009 4-7-2009
1 4-7-2010 
1 4-7-2011 
1 4-7-2012 
1 4-7-2013 
1 4-7-2014 4-7-2014
1 4-7-2015 
1 4-7-2016 
1 4-7-2018 
2 4-7-2005 4-7-2005
2 4-7-2011 4-7-2011 
2 4-7-2012 
2 4-7-2013 
2 4-7-2014 
2 4-7-2015 
2 4-7-2016 4-7-2016
2 4-7-2017 
2 4-7-2018 
2 4-7-2019 
2 4-7-2020 
;       
run; 

data want;
 if _n_=1 then do;
  dcl hash H () ;
  h.definekey  ("IDnumber") ;
  h.definedata ("index_date") ;
  h.definedone () ;
 end;
 do _n_=h.clear() by 0 until(last.IDnumber);
  set have;
  by IDnumber;
  if nmiss(index_date) then h.find();
  else h.replace();
  output;
 end;
run;
proc print noobs;run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1392 views
  • 1 like
  • 4 in conversation