Date: Thu, 5 Apr 2012 17:50:44 +0000
Reply-To: "Keintz, H. Mark" <mkeintz@WHARTON.UPENN.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Keintz, H. Mark" <mkeintz@WHARTON.UPENN.EDU>
Subject: Re: Inserting blank rows
In-Reply-To: <E0B423A8C0D1E74B8905B2C5CB38C1AF02FB3050@GENO3.wharton.upenn.edu>
Content-Type: text/plain; charset="us-ascii"
Randy et al.
MY mistake in my previous reply.
Instead of
DO I=1 to 4-_N;
I should have put
DO I=_N to 3;
--- corrected version follows ---------:
Randy:
If your goal is to faciliate a regression using lagged variables within groups of records (i.e. each DATE/IDA combination is a group), then there is a better solution than putting in three completely blank records between groups (I presume this means that you expect to use a 3-record lag somewhere).
Consider just setting the value of lagged fields to missing as appropriate when beginning a new group, as in:
data want (drop=_: );
retain _n 0;
set have;
by date ida;
if first.ida then _N=1;
else _n+1;
L3=lag3(vara);
L2=lag2(vara);
L1=lag1(vara);
array L {3} L1-L3;
if _N<=3 then do _I= _n to 3; L{_I}=.; end; run;
proc reg data=want;
by date ida;
model ..... ;
quit;
regards,
Mark
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Randy
Sent: Thursday, April 05, 2012 6:02 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Inserting blank rows
Dear All:
I want to insert blank rows at fixed points in the dataset. The reason is that I want to run regressions using lagged variables and I do not want an overlap.
My Dataset is as follows:
Date IDA IDB VarA
01MAR2012 1 1 4
01MAR2012 1 2 6
01MAR2012 1 3 3
01MAR2012 1 4 8
01MAR2012 1 5 2
02MAR2012 1 1 10
02MAR2012 1 2 14
02MAR2012 1 3 18
02MAR2012 1 4 4
01MAR2012 2 1 7
01MAR2012 2 2 3
01MAR2012 2 3 22
01MAR2012 2 4 14
01MAR2012 2 5 1
I want the data set to look as follows. I want to insert three rows after each Date and IDA
Date IDA IDB VarA
01MAR2012 1 1 4
01MAR2012 1 2 6
01MAR2012 1 3 3
01MAR2012 1 4 8
01MAR2012 1 5 2
02MAR2012 1 1 10
02MAR2012 1 2 14
02MAR2012 1 3 18
02MAR2012 1 4 4
01MAR2012 2 1 7
01MAR2012 2 2 3
01MAR2012 2 3 22
01MAR2012 2 4 14
01MAR2012 2 5 1
Randy