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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 366 views
  • 1 like
  • 2 in conversation