Hello
I want to create a new column called "Key".
For each customer there will be unique value from row with ind=1 until one row before the next ind=1.
What is the way to do it please?
Data have;
Input CustomerID Ind amount;
cards;
111 1 5000
111 0 200
111 0 210
111 0 205
111 0 208
111 1 8000
111 0 71
111 0 72
111 0 75
111 1 20000
222 1 7000
222 0 400
222 0 412
222 1 10000
222 0 101
222 0 99
222 0 102
;
Run;
Wanted data set
Data have;
Input CustomerID Ind amount;
cards;
111 1 5000
111 0 200
111 0 210
111 0 205
111 0 208
111 1 8000
111 0 71
111 0 72
111 0 75
111 1 20000
222 1 7000
222 0 400
222 0 412
222 1 10000
222 0 101
222 0 99
222 0 102
;
data want;
set have;
by CustomerID;
if Ind = 1 or first.CustomerID then key + 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 lock in 2025 pricing—just $495!
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.