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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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