Hello All,
I am trying to create a list where a certain string is deleted from a string list.
for example: considering the third row in the table below where year=2007M,2011M, the value 2007M,2011M should be deleted from year_list and with end result displayed in variable "want" being "2008,2009,2010". for this same example, the start should be 2007M, as that is the first observation in variable "year".
THe FINAL table that i want should be as follows:
year
year_list
want
2005M
2005M,2006,2007M,2008,2009,2010,2011M
2006,2007M,2008,2009,2010,2011M
2005M,2007M
2005M,2006,2007M,2008,2009,2010,2011M
2006,2008,2009,2010,2011M
2007M,2011M
2005M,2006,2007M,2008,2009,2010,2011M
2008,2009,2010
I tried arrays to solve this problem, but not able to get anywhere close to the first step.
I list below my code:
proc sql;
create table have (year VARCHAR(100), year_list VARCHAR(100));
insert into have values('2005M','2005M,2006,2007M,2008,2009,2010,2011M');
insert into have values('2005M,2007M','2005M,2006,2007M,2008,2009,2010,2011M');
insert into have values('2007M,2011M','2005M,2006,2007M,2008,2009,2010,2011M');
run;
data trial (keep=x);
set have(obs=1);
cnt=countw(year_list,",");
i=0;
do while (i<cnt);
i+1;
x=cats("dlv",scan(strip(year_list),i,","));
output;
end;
run;
proc sql ;
select distinct cats("mart",max(countw(year,","))), max(countw(year,",")) into :arraylist,:arraycnt from have;
select distinct cats("dlv",max(countw(year_list,","))), max(countw(year_list,",")) into :dlv_array, :dlvcnt from have;
select distinct x into :array_list separated by ' ' from trial;
run;
data want ;
set have;
length &array_list. $100.;
array dlv(&dlvcnt.) $ &array_list.;
do _j=1 to dim(dlv);
if index(upcase(vname(dlv(_j))),upcase(cats("DLV",dlv[_j]))) then do;
dlv[_j]=scan(year,_j,',');
end;
end;
run;
The array code in the last data step does not display the result i want for the first step of arriving to the final table. The table should look more like:
year
year_list
dlv2005M
dlv2006
dlv2007M
dlv2008
dlv2009
dlv2010
dlv2011M
2005M
2005M,2006,2007M,2008,2009,2010,2011M
2005M
2005M,2007M
2005M,2006,2007M,2008,2009,2010,2011M
2005M
2007M
2007M,2011M
2005M,2006,2007M,2008,2009,2010,2011M
2007M
2011M
After getting this table, I look at finding all missing values in the table and listing these out.
Still left with the dilemma of how to determine the first observation 😞
Any pointers, help, tip would be appreciated.
thanking you
... View more