BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
heretolearnSAS
Calcite | Level 5
cust_nodateobs_windowpoint
abc12320180110
abc12320180211
abc12320180312
abc12320180413
abc12320180520
abc12320180621
abc12320180722
def45620180310
def45620180411
def45620180520
def45620180621
def45620180722

 

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?

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

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;

View solution in original post

1 REPLY 1
japelin
Rhodochrosite | Level 12

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 711 views
  • 0 likes
  • 2 in conversation