From: Regi on 15 Jul 2010 03:41 Team, I have gone through other posts on the same subject but not able solve my problem. My requirement is to create lagged variables by group (city). I need to take lags by upto 4 periods. Can you please provide your suggestion? My data looks like below. DATA sur; INPUT city order deal; DATALINES; 11 1600 0.000 11 1601 0.000 11 1602 0.000 11 1603 95.607 11 1604 75.489 11 1605 64.283 14 1600 0.000 14 1601 0.000 14 1602 0.000 14 1603 110.626 14 1604 88.163 14 1605 75.075 ; Requirement is as below. city order deal deal1 deal2 deal3 deal4 11 1600 0.000 . . 11 1601 0.000 0.000 . 11 1602 0.000 0.000 0.000 11 1603 95.607 0.000 0.000 11 1604 75.489 95.607 0.000 11 1605 64.283 75.489 95.607 14 1600 0.000 . . 14 1601 0.000 0.000 . 14 1602 0.000 0.000 0.000 14 1603 110.626 0.000 0.000 14 1604 88.163 110.626 0.000 14 1605 75.075 88.163 110.626 14 1606 0.000 75.075 88.163
From: RolandRB on 15 Jul 2010 06:12 On Jul 15, 9:41 am, Regi <reg...(a)gmail.com> wrote: > Team, > > I have gone through other posts on the same subject but not able solve > my problem. My requirement is to create lagged variables by group > (city). I need to take lags by upto 4 periods. Can you please provide > your suggestion? > > My data looks like below. > > DATA sur; > INPUT city order deal; > DATALINES; > 11 1600 0.000 > 11 1601 0.000 > 11 1602 0.000 > 11 1603 95.607 > 11 1604 75.489 > 11 1605 64.283 > 14 1600 0.000 > 14 1601 0.000 > 14 1602 0.000 > 14 1603 110.626 > 14 1604 88.163 > 14 1605 75.075 > ; > > Requirement is as below. > > city order deal deal1 deal2 deal3 deal4 > 11 1600 0.000 . . > 11 1601 0.000 0.000 . > 11 1602 0.000 0.000 0.000 > 11 1603 95.607 0.000 0.000 > 11 1604 75.489 95.607 0.000 > 11 1605 64.283 75.489 95.607 > 14 1600 0.000 . . > 14 1601 0.000 0.000 . > 14 1602 0.000 0.000 0.000 > 14 1603 110.626 0.000 0.000 > 14 1604 88.163 110.626 0.000 > 14 1605 75.075 88.163 110.626 > 14 1606 0.000 75.075 88.163 It tells you how to do this on the sas support site here: http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#/documentation/cdl/en/lrdict/63026/HTML/default/a000212547.htm This is something like what you need but it is not clear how many previous deals you want to keep. data sur2; set sur; by city; array x{*} deal1-deal3; deal1=lag1(deal); deal2=lag2(deal); deal3=lag3(deal); if first.city then count=1; do i=count to dim(x); x(i)=.; end; count+1; drop count i; run; proc print data=sur2; run;
From: Regi on 17 Jul 2010 13:27 Thanks Roland for the solution and link. I could proceed with this help. Thanks, Regi
|
Pages: 1 Prev: Data Structure Logic Next: problem with reading from a file. one line in a few lines |