## Help with retain for 2 type of series (+ / -)

Solved
Super Contributor
Posts: 506

# Help with retain for 2 type of series (+ / -)

Hi Everyone,

I have the following data and my below code can assign order ( 1 2 3..) of a record in a series.

A series start when "Start" has value 1 or -1.

My problem I want to include the sign of the start into the order itself.

So for start 1, order will be 1 2 3 4...

So for start -1, order will be -1 -2 -3 -4...

I dont know how to do that step.

Thank you,

HHC

data have;

input time start;

datalines;

1 1

2 .

3 .

4 -1

5 .

6 1

7 -1

8 .

9 .

;

run;

data want; set have;

retain order;

if start in (1, -1) then order=0;

order=order+1;

run;

Accepted Solutions
Solution
‎11-29-2014 10:18 PM
Posts: 4,736

## Re: Help with retain for 2 type of series (+ / -)

Something like below could do:

data want;

set have;

retain order start_non_miss;

if start in (1, -1) then

do;

start_non_miss=start;

order=0;

end;

order=order+start_non_miss;

run;

All Replies
Solution
‎11-29-2014 10:18 PM
Posts: 4,736

## Re: Help with retain for 2 type of series (+ / -)

Something like below could do:

data want;

set have;

retain order start_non_miss;

if start in (1, -1) then

do;

start_non_miss=start;

order=0;

end;

order=order+start_non_miss;

run;

Super Contributor
Posts: 506

## Re: Help with retain for 2 type of series (+ / -)

Works perfectly.

Thank you.

HHC

🔒 This topic is solved and locked.