Hi! Here is a piece of code that gets what you want but not very elegantly:smileyplain: /*read in your data*/ data in ; input no year sal; cards; 10 2001 100 10 2002 102 11 2001 90 11 2002 12 11 2003 13 23 2002 100 23 2003 112 run; /*I want to change data from 'long' to 'wide*/ /*first need to sort*/ proc sort data = in;by no;run; data temp; set in; by no; /*create a couple of arrays, so now we have a column for each year and each sal*/ keep no yr2001-yr2003 t_sal2001-t_sal2003; retain yr2001-yr2003 t_sal2001-t_sal2003; array yr(2001:2003) yr2001-yr2003; array t_sal(2001:2003) t_sal2001-t_sal2003; if first.no then do; do i = 2001 to 2003; yr(i) = .; t_sal(i) = .; end; end; yr(year) = year; t_sal(year) = sal; if last.no then output; run; /*using a couple of IF-THEN we fill in the missing year*/ data temp_1; set temp; if yr2003 = . then do; if yr2002 ne . then yr2003 = yr2002; if t_sal2002 ne . then t_sal2003 = t_sal2002; n_entry2003 = "y"; end; if yr2001 = . then do; if yr2002 ne . then yr2001 = yr2002; if t_sal2002 ne . then t_sal2001 = t_sal2002; n_entry2001 = "y"; end; run; /*re-organize the data to long*/ data want; set temp_1; array yr(2001:2003) yr2001-yr2003; array t_sal(2001:2003) t_sal2001-t_sal2003; array n_entry(2001:2003) n_entry2001-n_entry2003; do i = 2001 to 2003; year = yr(i); sal = t_sal(i); new_entry = n_entry(i); output; end; drop yr: t_sal: n_entry:; run; There are probably more compact, efficient way to accomplish this...but this should get you started. Good luck! Anca.
... View more