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

Accepted Solution Solved
Reply
Super Contributor
Posts: 412
Accepted Solution

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.

Could you please help me with that?

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
Respected Advisor
Posts: 4,173

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;

View solution in original post


All Replies
Solution
‎11-29-2014 10:18 PM
Respected Advisor
Posts: 4,173

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: 412

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

Works perfectly.

Thank you.

HHC

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 302 views
  • 0 likes
  • 2 in conversation