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;
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;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.