LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (September 2011, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 1 Sep 2011 08:00:05 -0700
Reply-To:     jn mao <jn_mao@YAHOO.COM>
Sender:       "SAS(r) Discussion" <SAS-L@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
Comments: To: Daniel Nordlund <djnordlund@FRONTIER.COM>
In-Reply-To:  <9CCD79587F1D4179B183D61E5C0A4C30@Gandalf>
Content-Type: text/plain; charset=iso-8859-1

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: SAS-L@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 made-up 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 well-crafted solution.

Dan

Daniel Nordlund Bothell, WA USA

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of jn > mao > Sent: Wednesday, August 31, 2011 12:50 PM > To: SAS-L@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: SAS-L@LISTSERV.UGA.EDU > Date: Wednesday, August 31, 2011, 12:40 PM > > > -----Original Message----- > > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of jn > > mao > > Sent: Wednesday, August 31, 2011 9:55 AM > > To: SAS-L@LISTSERV.UGA.EDU > > Subject: How to compute difference between observations in longitudinal > > data format with marco > > > > Hi SAS-Ls, > > > > 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. > > %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] base1-base30; >          base_a[_n_] = visit; >        end; >        output; >     end; >   end; > > data want(keep= id diff_fac1-diff_fac30); >   set have; >   by id visit; >   array fv_a[30] _temporary_; >   array base_a[*] base1-base30; >   array diff_a[*] diff_fac1-diff_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_fac1-diff_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 98504-5204


Back to: Top of message | Previous page | Main SAS-L page