BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

Hello

Lets say I want to create a seq by group by the following way.

For each customer seq get same number until there is a change (Ind_change=1)

What is the way to create want data set?

 

data have;
input CustID Ind_Change;
cards;
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
2 0
2 0
2 1
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
3 0
3 0
3 1
3 0
3 1
3 0
3 0
3 0
3 0
3 0
3 0
3 0
4 1
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
;
Run;

data want;
input CustID Ind_Change seq;
cards;
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
1 0 1
2 0 1
2 0 1
2 1 1
2 0 1
2 0 1
2 0 1
2 0 1
2 0 1
2 0 1
2 0 1
2 0 1
2 0 1
3 0 1
3 0 1
3 1 2
3 0 2
3 1 3
3 0 3
3 0 3
3 0 3
3 0 3
3 0 3
3 0 3
3 0 3
4 1 1
4 0 1
4 0 1
4 0 1
4 0 1
4 0 1
4 0 1
4 0 1
4 0 1
4 0 1
4 0 1
4 0 1
;
Run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

I think it is easy for you ,isn't it ? Since you are using sas for so many years.

data have;
input CustID Ind_Change;
cards;
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
2 0
2 0
2 1
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
3 0
3 0
3 1
3 0
3 1
3 0
3 0
3 0
3 0
3 0
3 0
3 0
4 1
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
;
Run;
data want;
 set have;
 by CustID;
 if first.CustID then want=0;
 if first.CustID or Ind_Change=1 then want+1;
run;

View solution in original post

1 REPLY 1
Ksharp
Super User

I think it is easy for you ,isn't it ? Since you are using sas for so many years.

data have;
input CustID Ind_Change;
cards;
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
2 0
2 0
2 1
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
3 0
3 0
3 1
3 0
3 1
3 0
3 0
3 0
3 0
3 0
3 0
3 0
4 1
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
4 0
;
Run;
data want;
 set have;
 by CustID;
 if first.CustID then want=0;
 if first.CustID or Ind_Change=1 then want+1;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 302 views
  • 1 like
  • 2 in conversation