From: shashi on
Hi,
I have a variable 'visit', like mentioned below. Corresponding to this
variable I need one more variable 'RepeatNumber' which contains 111
for every first Unscheduled visit between two consecutive scheduled
visits and the next Unscheduled visit should be 2.1, 2.2, 2.3 etc., if
the unscheduled visits are after the scheduled visit 2.


Can anybody suggest over getting the variable 'RepeatNumber' based on
'visit'?


visit RepeatNumber
1 .
2 .
UNSCHEDULED 111
UNSCHEDULED 2.1
UNSCHEDULED 2.2
UNSCHEDULED 2.3
3 .
4 .
5 .
UNSCHEDULED 111
UNSCHEDULED 5.1
UNSCHEDULED 5.2
6 .
7 .
UNSCHEDULED 111
UNSCHEDULED 7.1
UNSCHEDULED 7.2
UNSCHEDULED 7.3
UNSCHEDULED 7.4

Thanks in advance,
Shashi
From: "Data _null_;" on
How does you sample data represent when there are not "two consecutive
scheduled visits". What happens in that situation?

Part of the key to this processing is the NOTSORTED BY statement
option. But I don't deal with the consecutive qualification in the
following example.

data test;
input subjid:$3. visit :$11.;
cards;
101 1
101 2
101 UNSCHEDULED
101 UNSCHEDULED
101 UNSCHEDULED
101 UNSCHEDULED
101 3
101 4
101 5
101 UNSCHEDULED
101 UNSCHEDULED
101 UNSCHEDULED
101 6
101 7
101 UNSCHEDULED
101 UNSCHEDULED
101 UNSCHEDULED
101 UNSCHEDULED
101 UNSCHEDULED
103 1
103 2
103 UNSCHEDULED
103 UNSCHEDULED
103 UNSCHEDULED
103 UNSCHEDULED
103 3
103 4
103 5
103 UNSCHEDULED
103 UNSCHEDULED
103 UNSCHEDULED
103 6
103 7
103 UNSCHEDULED
103 UNSCHEDULED
103 UNSCHEDULED
103 UNSCHEDULED
103 UNSCHEDULED
;;;;
run;
data test2;
do until(last.subjid);
set test;
by notsorted subjid visit;
if visit ne: 'U' then s=input(visit,f8.);
else do;
if first.visit then do;
repeatNumber = 111;
r = 0;
end;
else do;
r + .1;
repeatnumber = s+r;
end;
end;
output;
call missing(repeatnumber);
end;
format repeatnumber best5.;
drop s r;
run;
proc print;
run;

On 12/7/09, shashi <shashi2707(a)gmail.com> wrote:
> Hi,
> I have a variable 'visit', like mentioned below. Corresponding to this
> variable I need one more variable 'RepeatNumber' which contains 111
> for every first Unscheduled visit between two consecutive scheduled
> visits and the next Unscheduled visit should be 2.1, 2.2, 2.3 etc., if
> the unscheduled visits are after the scheduled visit 2.
>
>
> Can anybody suggest over getting the variable 'RepeatNumber' based on
> 'visit'?
>
>
> visit RepeatNumber
> 1 .
> 2 .
> UNSCHEDULED 111
> UNSCHEDULED 2.1
> UNSCHEDULED 2.2
> UNSCHEDULED 2.3
> 3 .
> 4 .
> 5 .
> UNSCHEDULED 111
> UNSCHEDULED 5.1
> UNSCHEDULED 5.2
> 6 .
> 7 .
> UNSCHEDULED 111
> UNSCHEDULED 7.1
> UNSCHEDULED 7.2
> UNSCHEDULED 7.3
> UNSCHEDULED 7.4
>
> Thanks in advance,
> Shashi
>