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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.