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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 385 views
  • 0 likes
  • 2 in conversation