Date: Thu, 1 Sep 2011 08:00:05 0700
ReplyTo: jn mao <jn_mao@YAHOO.COM>
Sender: "SAS(r) Discussion" <SASL@LISTSERV.UGA.EDU>
From: jn mao <jn_mao@YAHOO.COM>
Subject: Thanks Much! Re: How to compute difference between observations
in longitudinal data format with marco
InReplyTo: <9CCD79587F1D4179B183D61E5C0A4C30@Gandalf>
ContentType: text/plain; charset=iso88591
Thanks much! It works out.
Jane
 On Wed, 8/31/11, Daniel Nordlund <djnordlund@FRONTIER.COM> wrote:
From: Daniel Nordlund <djnordlund@FRONTIER.COM>
Subject: Re: How to compute difference between observations in longitudinal data format with marco
To: SASL@LISTSERV.UGA.EDU
Date: Wednesday, August 31, 2011, 6:00 PM
Jane,
I probably just confused you because I don't know what your real file names are, and I don't know what your variable names really are, and I only have a vague idea of what your desired outcome is. (But I am pretty sure it doesn't require macro language.)
The first datastep in my example was just madeup data because you didn't give any data to work with. For your problem, you should just ignore that datastep.
In the second datastep, you would need to substitute your dataset file name in place of the name HAVE on the SET statement and use YOUR variable names in the array definitions and in the KEEP statement. You will also need to keep the GROUP variable if you want to use that in subsequent steps.
If you need more specific assistance, then as has been suggested, you will need to give us an example of your data (a few clients and all the relevant variables). Then someone can provide a wellcrafted solution.
Dan
Daniel Nordlund
Bothell, WA USA
> Original Message
> From: SAS(r) Discussion [mailto:SASL@LISTSERV.UGA.EDU] On Behalf Of jn
> mao
> Sent: Wednesday, August 31, 2011 12:50 PM
> To: SASL@LISTSERV.UGA.EDU
> Subject: Re: How to compute difference between observations in
> longitudinal data format with marco
>
> Thanks Dan, I tried several times with your code. Don't understand why
> they all become missing data. Does your id means the patients ID? if yes,
> then the total data after 1st part run, increased to original data x
> 5(visit) x 200( ID= total patients number), so after first part run, my
> total data from 200 to 200000, right?
>
>  On Wed, 8/31/11, Nordlund, Dan (DSHS/RDA) <NordlDJ@DSHS.WA.GOV> wrote:
>
> From: Nordlund, Dan (DSHS/RDA) <NordlDJ@DSHS.WA.GOV>
> Subject: Re: How to compute difference between observations in
> longitudinal data format with marco
> To: SASL@LISTSERV.UGA.EDU
> Date: Wednesday, August 31, 2011, 12:40 PM
>
> > Original Message
> > From: SAS(r) Discussion [mailto:SASL@LISTSERV.UGA.EDU] On Behalf Of jn
> > mao
> > Sent: Wednesday, August 31, 2011 9:55 AM
> > To: SASL@LISTSERV.UGA.EDU
> > Subject: How to compute difference between observations in longitudinal
> > data format with marco
> >
> > Hi SASLs,
> >
> > I have over 30 variables with 5 followup 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.
> > %macro prepo;
> > %do i=1 %to 40;
> > IF FIRST.visit THEN DO;
> > fac&i=base&i;
> > END;
> > IF LAST.visit THEN DO;
> > DIFF_fac&i = fac&i  base&i;
> > OUTPUT;
> > END;
> > proc univariate ;
> > class group;
> > var diff_fac&i;
> > %end;
> > %mend;
> >
> > Can someone help me out? Thanks much!
> >
>
> Jane,
>
> You haven't provided enough detail to give an exact solution, but I went
> ahead and made some guesses. If I have guessed right, you don't need to
> do this in a macro. Here is one option. I have made up some data to work
> with.
>
> data have ;
> do id = 1 to 5;
> do visit = 1 to 5;
> do _n_= 1 to 30;
> array base_a[30] base1base30;
> base_a[_n_] = visit;
> end;
> output;
> end;
> end;
>
> data want(keep= id diff_fac1diff_fac30);
> set have;
> by id visit;
> array fv_a[30] _temporary_;
> array base_a[*] base1base30;
> array diff_a[*] diff_fac1diff_fac30;
>
> if first.id then do _n_ = 1 to 30;
> fv_a[_n_] = base_a[_n_];
> end;
> if last.id then do;
> do _n_ = 1 to 30;
> diff_a[_n_] = fv_a[_n_]  base_a[_n_];
> end;
> output;
> end;
> run;
> proc univariate ;
> class group;
> var diff_fac1diff_fac30;
> end;
>
>
> If this doesn't get you started, then provide us some code to generate
> data that we can work with, and show us the final output that you want.
> (I didn't include a group variable in my test data so the proc univariate
> won't run, but that shouldn't be a problem for your data.)
>
>
> Hope this is helpful,
>
> Dan
>
> Daniel J. Nordlund
> Washington State Department of Social and Health Services
> Planning, Performance, and Accountability
> Research and Data Analysis Division
> Olympia, WA 985045204
