BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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

Ronein_0-1662969087644.png

 

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20
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;
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
  • 845 views
  • 1 like
  • 2 in conversation