Some code change make it work, data values in the DATA Step where delimited by a tab char changed to comma.
Add another join condition for the id.
data have;
infile cards dlm=",";
input id time value $;
datalines;
1,86,A
1,87,B
1,88,C
1,89,D
1,90,E
2,86,D
2,87,E
2,88,A
2,89,C
2,90,B
;
run;
proc sql;
create table want as
select
have1.*
, case
when have2.time is null then have1.time+1
else have2.time
end as time_1
, case
when have2.value is null then "n/a"
else have2.value
end as value_1
from
have have1
left join
have have2
on
have1.id = have2.id
and have1.time=have2.time-1
order by
have1.id
,have1.time
;
quit;
... View more