Hi
Its been a long time since I programmed - so i am a bit rusty.
I have a dataset that contains deltas (only populated when a value
changes). The dataset has an id, a weekending date, and the value of
the value that changes. All items are initialised at the beginnning
of the quarter. I need to fill in the gaps between the first week
(when the value is set) to the first delta, and then keep the delta
value until the second delta and so on.
My file looks something like this:
data test;
format dater date9.;
input dateEvent date9. id val $;
datalines;
7-Jul-09 1 a
8-Sep-09 2 a
29-Sep-09 2 a
7-Jul-09 3 a
18-Aug-09 3 a
4-Aug-09 1 b
18-Aug-09 2 b
28-Jul-09 3 b
22-Sep-09 3 b
22-Sep-09 1 c
28-Jul-09 2 c
4-Aug-09 3 c
29-Sep-09 1 d
7-Jul-09 2 d
;
run;
What I would like is to have a file that has, for the id of 1,:
7-Jul-09 1 a
14-Jul-09 1 a
21-Jul-09 1 a
28-Jul-09 1 a
4-Aug-09 1 b
11-Aug-09 1 b
18-Aug-09 1 b
25-Aug-09 1 b
1-Sep-09 1 b
8-Sep-09 1 b
15-Sep-09 1 b
22-Sep-09 1 c
29-Sep-09 1 d
I have tried to recall old code that uses ratains and first. items but
I seem to be getting nowhere.
In sumary, I want to populate the missing weeks for each record and
then retain the value for each Id until it changes. any assistance
greately appreciated.
Doug
|
|
0
|
|
|
|
Reply
|
jerrabomberra (5)
|
4/21/2010 12:35:17 PM |
|
On Apr 21, 7:35=A0am, Doug <jerrabombe...@gmail.com> wrote:
> Hi
>
> Its been a long time since I programmed - so i am a bit rusty.
>
> I have a dataset that contains deltas (only populated when a value
> changes). =A0The dataset has an id, a weekending date, and the value of
> the value that changes. =A0All items are initialised at the beginnning
> of the quarter. =A0I need to fill in the gaps between the first week
> (when the value is set) to the first delta, and then keep the delta
> value until the second delta and so on.
> =A0My file looks something like this:
> data test;
> format dater date9.;
> input dateEvent =A0date9. id val $;
> datalines;
> 7-Jul-09 =A0 =A0 =A0 =A01 =A0 =A0 =A0 a
> 8-Sep-09 =A0 =A0 =A0 =A02 =A0 =A0 =A0 a
> 29-Sep-09 =A0 2 =A0 a
> 7-Jul-09 =A0 =A0 =A0 =A03 =A0 =A0 =A0 a
> 18-Aug-09 =A0 =A0 =A0 3 =A0 =A0 =A0 a
> 4-Aug-09 =A0 =A0 =A0 =A01 =A0 =A0 =A0 b
> 18-Aug-09 =A0 =A0 =A0 2 =A0 =A0 =A0 b
> 28-Jul-09 =A0 =A0 =A0 3 =A0 =A0 =A0 b
> 22-Sep-09 =A0 =A0 =A0 3 =A0 =A0 =A0 b
> 22-Sep-09 =A0 =A0 =A0 1 =A0 =A0 =A0 c
> 28-Jul-09 =A0 =A0 =A0 2 =A0 =A0 =A0 c
> 4-Aug-09 =A0 =A0 =A0 =A03 =A0 =A0 =A0 c
> 29-Sep-09 =A0 =A0 =A0 1 =A0 =A0 =A0 d
> 7-Jul-09 =A0 =A0 =A0 =A02 =A0 =A0 =A0 d
> ;
> run;
>
> What I would like is to have a file that has, for the id of 1,:
> 7-Jul-09 =A0 =A0 =A0 =A01 =A0 =A0 =A0 a
> 14-Jul-09 =A0 =A0 =A0 1 =A0 =A0 =A0 a
> 21-Jul-09 =A0 =A0 =A0 1 =A0 =A0 =A0 a
> 28-Jul-09 =A0 =A0 =A0 1 =A0 =A0 =A0 a
> 4-Aug-09 =A0 1 =A0 =A0 =A0b
> 11-Aug-09 =A0 1 =A0 =A0 b
> 18-Aug-09 =A0 1 =A0 =A0 b
> 25-Aug-09 =A0 1 =A0 =A0 b
> 1-Sep-09 =A0 =A01 =A0 =A0 =A0b
> 8-Sep-09 =A0 =A01 =A0 =A0 =A0b
> 15-Sep-09 =A01 =A0 =A0 =A0b
> 22-Sep-09 =A0 =A0 =A0 1 =A0 =A0 =A0 c
> 29-Sep-09 =A0 =A0 =A0 1 =A0 =A0 =A0 d
>
> I have tried to recall old code that uses ratains and first. items but
> I seem to be getting nowhere.
>
> In sumary, I want to populate the missing weeks for each record and
> then retain the value for each Id until it changes. =A0any assistance
> greately appreciated.
>
> Doug
This method assumes the date range is the same for all subjects.
1) determine the range.
2) create weekly obs
3) expand the data
4) locf
|
|
0
|
|
|
|
Reply
|
data
|
4/21/2010 6:32:00 PM
|
|
On Apr 21, 1:32=A0pm, "data _null_;" <datan...@gmail.com> wrote:
> On Apr 21, 7:35=A0am, Doug <jerrabombe...@gmail.com> wrote:
>
>
>
>
>
> > Hi
>
> > Its been a long time since I programmed - so i am a bit rusty.
>
> > I have a dataset that contains deltas (only populated when a value
> > changes). =A0The dataset has an id, a weekending date, and the value of
> > the value that changes. =A0All items are initialised at the beginnning
> > of the quarter. =A0I need to fill in the gaps between the first week
> > (when the value is set) to the first delta, and then keep the delta
> > value until the second delta and so on.
> > =A0My file looks something like this:
> > data test;
> > format dater date9.;
> > input dateEvent =A0date9. id val $;
> > datalines;
> > 7-Jul-09 =A0 =A0 =A0 =A01 =A0 =A0 =A0 a
> > 8-Sep-09 =A0 =A0 =A0 =A02 =A0 =A0 =A0 a
> > 29-Sep-09 =A0 2 =A0 a
> > 7-Jul-09 =A0 =A0 =A0 =A03 =A0 =A0 =A0 a
> > 18-Aug-09 =A0 =A0 =A0 3 =A0 =A0 =A0 a
> > 4-Aug-09 =A0 =A0 =A0 =A01 =A0 =A0 =A0 b
> > 18-Aug-09 =A0 =A0 =A0 2 =A0 =A0 =A0 b
> > 28-Jul-09 =A0 =A0 =A0 3 =A0 =A0 =A0 b
> > 22-Sep-09 =A0 =A0 =A0 3 =A0 =A0 =A0 b
> > 22-Sep-09 =A0 =A0 =A0 1 =A0 =A0 =A0 c
> > 28-Jul-09 =A0 =A0 =A0 2 =A0 =A0 =A0 c
> > 4-Aug-09 =A0 =A0 =A0 =A03 =A0 =A0 =A0 c
> > 29-Sep-09 =A0 =A0 =A0 1 =A0 =A0 =A0 d
> > 7-Jul-09 =A0 =A0 =A0 =A02 =A0 =A0 =A0 d
> > ;
> > run;
>
> > What I would like is to have a file that has, for the id of 1,:
> > 7-Jul-09 =A0 =A0 =A0 =A01 =A0 =A0 =A0 a
> > 14-Jul-09 =A0 =A0 =A0 1 =A0 =A0 =A0 a
> > 21-Jul-09 =A0 =A0 =A0 1 =A0 =A0 =A0 a
> > 28-Jul-09 =A0 =A0 =A0 1 =A0 =A0 =A0 a
> > 4-Aug-09 =A0 1 =A0 =A0 =A0b
> > 11-Aug-09 =A0 1 =A0 =A0 b
> > 18-Aug-09 =A0 1 =A0 =A0 b
> > 25-Aug-09 =A0 1 =A0 =A0 b
> > 1-Sep-09 =A0 =A01 =A0 =A0 =A0b
> > 8-Sep-09 =A0 =A01 =A0 =A0 =A0b
> > 15-Sep-09 =A01 =A0 =A0 =A0b
> > 22-Sep-09 =A0 =A0 =A0 1 =A0 =A0 =A0 c
> > 29-Sep-09 =A0 =A0 =A0 1 =A0 =A0 =A0 d
>
> > I have tried to recall old code that uses ratains and first. items but
> > I seem to be getting nowhere.
>
> > In sumary, I want to populate the missing weeks for each record and
> > then retain the value for each Id until it changes. =A0any assistance
> > greately appreciated.
>
> > Doug
>
> This method assumes the date range is the same for all subjects.
>
> 1) determine the range.
> 2) create weekly obs
> 3) expand the data
> 4) locf- Hide quoted text -
>
> - Show quoted text -
Opps forgot the program
data test;
input dateEvent:date. id val $;
format dateEvent date9.;
datalines;
7-Jul-09 1 a
8-Sep-09 2 a
29-Sep-09 2 a
7-Jul-09 3 a
18-Aug-09 3 a
4-Aug-09 1 b
18-Aug-09 2 b
28-Jul-09 3 b
22-Sep-09 3 b
22-Sep-09 1 c
28-Jul-09 2 c
4-Aug-09 3 c
29-Sep-09 1 d
7-Jul-09 2 d
;
run;
proc sort;
by id dateEvent;
run;
proc summary data=3Dtest;
output out=3Drange(drop=3D_:) max(dateEvent)=3Dmax min(dateEvent)=3Dmin;
run;
data classdata;
if 0 then set test(keep=3Ddateevent);
set range;
do w=3D0 to intck('WEEK',min,max);
dateevent =3D intnx('WEEK',min,w,'sameday');
output;
end;
stop;
run;
proc print;
run;
proc summary data=3Dtest classdata=3Dclassdata nway;
by id;
class date:;
output out=3Dexpanded(drop=3D_:) idgroup(out(val)=3D);
run;
data locf;
do until(last.id);
set expanded;
by id;
length locf $1.;
locf =3D coalesceC(val,locf);
output;
end;
run;
proc print;
run;
|
|
0
|
|
|
|
Reply
|
data
|
4/21/2010 6:32:58 PM
|
|
|
2 Replies
163 Views
(page loaded in 0.08 seconds)
Similiar Articles: Good 1D interpolation source code in C/C++? - comp.programming ...Hi all, Let's say in a sequence of 1D data, there are NaN's(not a valid number), how do I interpolate the sequence and fill in the gaps/holes of NaN'... Filling Blanks Between 2 Values - comp.soft-sys.sas... set test end=last; y+(present='Y'); lastP=present; end; /*fill the gap and ... How to fill a matrix without ... comp.soft-sys.matlab ..... 308], the increment between ... Does anyone recognize this problems with PSP8 - comp.graphics.apps ...[snip] That cross hatched pattern is what PSP uses to fill in the gap when the viewing window is larger than the image. If you press Ctrl+W, the window should shrink to ... Convert Assembly to Single Solid - comp.cad.solidworks... 1 to have surface only, 2 all parts and 3 outer parts and then your assembly (the saved part) will be a single part. Then u can check for small gaps and fill that gap ... find sequences of 1's - comp.soft-sys.matlabI have a matrix of 1's and 0's. I want to go through the matrix column for column and find sequences of 1's and also find the length of these sequenc... ndft (non-uniform discrete fourier transform) and reconstructing ...My memory is not good these days however, I think that I was able to use this to fill the gap in the 15 point straight line [ 1:12, 15:17 ] of the OP. Pattern fill uses undesired linetype - comp.graphics.apps.gnuplot ...My relevant plot commands: set style data histogram; set style fill pattern border -1; set style histogram cluster gap 3; set term post eps "Helvetica" 16 ... Line command in NetBSD ed - comp.unix.bsd.netbsd.miscTcl/TK is indeed dying - comp.lang.tcl I also leverage system/command-line tools to fill in gaps in ... You might have a look at 'ed', as "ed is the ... with an old laptop ... Edge Linking for curved edges - comp.soft-sys.matlabYou could fill all the blobs (edges) in your binary image, and then label all the ... work only for gaps smaller than the kernel window, and not in general for any gap ... Commercial Fortran Compilers - comp.lang.fortranThat is when most of the fortran compilers starting using the C preprocessor to fill this gap in functionality. The COCO/fpp preprocessor came much later (f95, I ... How to Fill Concrete Gaps | eHow.comGaps in concrete, whether they result from cracks in the slab or occur between the slab and an adjacent surface, can serve as openings that allow dirt, moisture or ... Filling the GapsWelcome to Filling The Gaps! Filling The Gaps is a fully recognized 501(c) 3 California based non profit. It was created to help provide tuition ... 7/17/2012 7:19:54 AM
|