From: rangoon rangoon on
I want to convert data have to data want with new variable ndate
created in such a way that

for each sub if param = XXXX then the corresponding date should be
put in ndate and retained till it sees another param = XXXX but if
there is no param = BILITOT between param = XXXX then the first date
should be retained.(as in the case of 1).

I hope the data will help.


data have;

sub date
param

1 23MAY2008 xxxx
1 23MAY2008 BILITOT
1 26MAY2008 xxxx
1 27MAY2008 xxxx
1 28MAY2008 xxxx
1 28MAY2008 BILITOT

2 11JAN2008 BILITOT
2 15JAN2008 BILITOT
2 16NOV2008 xxxx
2 16NOV2008 BILITOT
2 18NOV2008 BILITOT
2 19NOV2008 BILITOT

run;

data want;

sub date param ndate

1 23MAY2008 xxxx 23MAY2008
1 23MAY2008 BILITOT 23MAY2008
1 26MAY2008 xxxx 26MAY2008
1 27MAY2008 xxxx 26MAY2008
1 28MAY2008 xxxx 26MAY2008
1 28MAY2008 BILITOT 26MAY2008

2 11JAN2008 BILITOT 11JAN2008
2 15JAN2008 BILITOT 15JAN2008
2 16NOV2008 xxxx 16NOV2008
2 16NOV2008 BILITOT 16NOV2008
2 18NOV2008 BILITOT 16NOV2008
2 19NOV2008 BILITOT 16NOV2008

From: Oleg on
Greetings.

Try this code.

data have;
infile cards;
informat sub 8. date date9. param $7.;
input sub date param;
format date date9.;
cards;
1 23MAY2008 xxxx
1 23MAY2008 BILITOT
1 26MAY2008 xxxx
1 27MAY2008 xxxx
1 28MAY2008 xxxx
1 28MAY2008 BILITOT
2 11JAN2008 BILITOT
2 15JAN2008 BILITOT
2 16NOV2008 xxxx
2 16NOV2008 BILITOT
2 18NOV2008 BILITOT
2 19NOV2008 BILITOT
;


data want; retain ndate 8.; set have ; by sub;
if first.sub then ndate=date;
else if upcase(param)='XXXX' then ndate=date;
format ndate date9.;
run;