/*Create dataset*/ data create_data; infile datalines; input id t base value; datalines; 1 1 5.053078 14.61624 1 5 5.687529 36.09745 1 7 4.149219 45.9342 1 14 3.342423 72.15495 ; run;
data want; set create_data end=last; by id t; /*Initialize variables*/ retain t_first 0 base1 0 t_first 0 t_last 0 value_last 0 t_diff 0 value_diff 0; /*Read base and t values for first observation*/ if first.id then do; base1=base; t_first=t; end; /*Read t and value values from last observation*/ if last.id then do; t_last=t; value_last=value; end; /*Perform calculation*/ t_diff=t_last - t_first; value_diff=value_last-base1; /*Subset the dataset for the last observation*/ if last then output; run;
proc print data=want noobs; /*Displaying variables of interest*/ var t_first t_last t_diff base1 value_last value_diff; run;
... View more