The data step solution is to use arrays and FIRST./LAST. processing.
array orig var1-var30;
array base (30);
array final (30);
array diff (30);
do until (last.id);
by id visit;
if first.visit then do i=1 to 30;
if not first.visit then do i=1 to 30;
final(i) = orig(i);
do i=1 to 30;
diff(i) = final(i) - orig(i);
If you just want the differences then you can get them using PROC COMPARE
also. Here is an example constructed from the SASHELP.CLASS dataset with a
little random noise added to the WEIGHT variable. Requires that you can
identify the last visit for each subject.
do visit=1 to 3 ;
do p=1 to nobs;
set sashelp.class point=p nobs=nobs;
weight = weight + 10*ranuni(0);
outdiff out=diff ;
id name ;
var weight height ;
proc print data=diff; run;
On Wed, 31 Aug 2011 09:55:29 -0700, jn mao <jn_mao@YAHOO.COM> wrote:
>I have over 30 variables with 5 follow-up data. I need to compute the
difference between the 1st visit and the last visit. Can someone help me it
in SAS with macro?
>Here are my code, but seems I can't use if and then in macro.
>%do i=1 %to 40;
>IF FIRST.visit THEN DO;
>IF LAST.visit THEN DO;
>DIFF_fac&i = fac&i - base&i;
>proc univariate ;
>Can someone help me out? Thanks much!