cust_no | date | obs_window | point |
abc123 | 201801 | 1 | 0 |
abc123 | 201802 | 1 | 1 |
abc123 | 201803 | 1 | 2 |
abc123 | 201804 | 1 | 3 |
abc123 | 201805 | 2 | 0 |
abc123 | 201806 | 2 | 1 |
abc123 | 201807 | 2 | 2 |
def456 | 201803 | 1 | 0 |
def456 | 201804 | 1 | 1 |
def456 | 201805 | 2 | 0 |
def456 | 201806 | 2 | 1 |
def456 | 201807 | 2 | 2 |
Hello guys, let's assume the above is my dataset, and the "point" is the column I want to create. In this case, I wish to create the input for the "point" column starting with 0 for the first observed observation of each customer, and +1 thereafter. However, if obs_window is different, then the point will restart again for a customer.
the current code I'm using is as below:
data mydataset;
set dataset;
by cust_no;
if first.cust_no then point = 0;
else point +1;
in this case, how should I tune the above code?
I assume it is sorted by cust_no obs_window.
data mydataset;
set have;
by cust_no obs_window;
if first.obs_window then point = 0;
else point +1;
run;
I assume it is sorted by cust_no obs_window.
data mydataset;
set have;
by cust_no obs_window;
if first.obs_window then point = 0;
else point +1;
run;
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.