Hi,
It is unclearn, at leat to me, what You are trying to achieve.
As RW9 said, it could be useful to take some time to think about
which form should take your data to make your work simpler.
Since we are dealing with years, Yu'd probably prefer using
numeric variables.
For instance, year_list seems identical for all observations and contains
consecutive years. So all you need is the first and the last year.
You can store them in macro-variables to avoid repeating them on each observation.
Does the following code answer your problem ?
proc sql; create table have (year VARCHAR(100), year_list VARCHAR(100)); insert into have values('2005','2005,2006,2007,2008,2009,2010,2011'); insert into have values('2005,2007','2005,2006,2007,2008,2009,2010,2011'); insert into have values('2007,2011','2005,2006,2007,2008,2009,2010,2011'); run; %let period_start=2005; %let period_end=2011; data do_you_want_this; set have; format start end 4. want $1000.; start = max(put(scan(year,1,','),4.)+1,&period_start.); end = &period_end.-1; exclude = put(scan(year,2,','),4.); do i=start to end; if i ne exclude then want=catx(',',want,i); end; drop exclude i; run;
... View more