LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 10 Jan 2008 10:11:44 -0600
Reply-To:     "data _null_," <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "data _null_," <datanull@GMAIL.COM>
Subject:      Re: New problem with data manipulation. Thanks!!!
Comments: To: olivesecret@gmail.com
In-Reply-To:  <4e82b0f4-485c-441c-b238-1fb7d2e82a31@z17g2000hsg.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1

Using do until(last.byvarible) and the IFN function you can simplify the code somewhat, but basically works the same way as the other offerings. If you are offended by the propagation of missing values then Px1-Px3 could be initialized to 1, at the top of the data step. You could also utilize and array if you have more variables. But as Tody mentioned, but did not explain, if you restructure the data the problem might be simpler.

data work.A; input id visit i x1 x2 x3; datalines; 1 1 1 0.1 1 1 1 1 2 2 0.1 4 1 1 3 1 1 0.1 1 2 2 1 1 1 2 1 3 0.1 1 1 ;;;; run; data work.cprod; do until(last.visit); set work.a; by id visit; Px1 = ifn(first.visit,x1,px1*x1); Px2 = ifn(first.visit,x2,px2*x2); Px3 = ifn(first.visit,x3,px3*x3); output; end; run; proc print; run;

On Jan 10, 2008 9:28 AM, <olivesecret@gmail.com> wrote: > I met a new problem with data manipulation. Say I have a dataset like: > > data A; > input id visit i x1 x2 x3; > datalines; > 1 1 1 0.1 1 1 > 1 1 2 1 0.1 1 > 1 1 3 1 1 0.1 > 1 2 2 1 1 1 > 2 1 3 0.1 1 1 > . > . > . > ; > run; > > For data A, for obs with same id and visit, I want to get the > cumulative product of x1, x2 and x3. That is, the new dataset B with > first 3 obs as: > 1 1 3 0.1 0.1 0.1 > 1 2 2 1 1 1 > 2 1 3 0.1 1 1 > > Since the first 3 obs of A have same id and visit, x1=0.1*1*1, > x2=1*0.1*1 and x3=1*1*0.1. > > How can I do it in SAS? I tried different ways from the hints I got > from your guys to my earlier question, but unsuccessful... > > Thanks! > > Olive >


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