09-21-2011 06:11 PM
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:
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.
09-21-2011 06:27 PM
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?
09-22-2011 01:27 AM
If the order were the same with the order at your post.
That will be easy.
if date_of _purchase ne lag(date_of_purchase) then count+1;