BookmarkSubscribeRSS Feed
justchecking
Calcite | Level 5

Okay - I realize this is probably extremely easy to do in SAS but I for the life cannot figure it out - everything I've tried has not worked the way I need it to and am at my wits end.  Any help would be greatly appreciated.

Let's say I have the following dataset in my work direcotry that consist of the first name of a customer and their date of purchase:

First_Name
Date_of_Purchase
John

01/01/2010

Jill

01/01/2010

Beth01/01/2010
Will02/01/2010
Jen

02/01/2010

Lori03/01/2010
Tom03/01/2010
Heidi04/01/2010

What I need to do is an incremental count based on the change in date_of_purchase starting with the value of 1, results of which is shown below.  I've tried various do-loop statements but cannot seem to populate the variable count with the value  when the date remains unchanged (for example, for 01/01/2010, I've no problem populating first.date_of_purchase with 1, but subsequent cells under Count tied to 01/01/2010 remain empty.  I've about 3 years worth of purchase data, with over thousand of customers.  Thanks!  If any clarification is needed, don't hestitate to let me know. 

First_Name
Date_of_PurchaseCount
John

01/01/2010

1
Jill

01/01/2010

1
Beth01/01/20101
Will02/01/20102
Jen

02/01/2010

2
Lori03/01/20103
Tom03/01/20103
Heidi04/01/20104
3 REPLIES 3
art297
Opal | Level 21

Are you trying to increment based on number of purchases (which aren't shown in your sample data) or simply by number of months since 1JAN2010?

Howles
Quartz | Level 8

data want ;

set have ;

by Date_of_Purchase ;

Count + first.Date_of_Purchase ;

run ;

Ksharp
Super User

If the order were the same with the order at your post.

That will be easy.

data want;

set have;

if date_of _purchase ne lag(date_of_purchase) then count+1;

run;

Ksharp

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1952 views
  • 0 likes
  • 4 in conversation