BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Renan_Crepaldi
Obsidian | Level 7

Hello!

 

I have a data set that contains the Ids of my customers and their registration's date, besides the date each one made their first purchase (if they did it, meaning there are null values on this column):

 

DATA EXAMPLE.JPG

 

I wanted to group them by the year and month of registration (Example: all customers registered on January/2019) and make a cumulative count of how many months it took for the first purchase, starting from their registration month until now. So if a customer that registered on January/2019 made his first purchase on February/2019, I want to count him from this month forward.

 

The objective is to compare if the recent customers are taking longer to start buying.

 

I imagine that the final data set would be somethin like this:

 

RESULTS EXAMPLE.JPG

 

My final objective is to make a graphic comparing the % of each batch, similar to the example below:

 

GRAPHIC EXAMPLE.JPG

 

Anyone knows how I could develop a data set in these conditions?

 

Sorry if my question is not clear enough, and I am available to give more details if necessary.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

So, the INTCK function determines how many months, and PROC FREQ computes the number.

 

data have2;
    set have;
    months=intck('month',registrationdate,firstpurchasedate);
run;
proc freq data=have2;
    tables registrationdate*months/noprint list out=_counts_;
run;
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

It would be extremely helpful if you could provide actual SAS data set as  DATA step code, rather than this screen capture of the data in some other program. In particular, we need to know if the dates you are showing are actual SAS dates, or SAS date/times values, or something else. Until I have that, I'm going to avoid providing specific code ...

 

Nevertheless, the difference in months between registration date and first purchase date is computed easily enough by the INTCK function. Once you have the difference in months, PROC FREQ will allow you to obtain the counts as you have shown in your second table.

--
Paige Miller
Renan_Crepaldi
Obsidian | Level 7

Hi, Paige.

 

Thanks for replying! I tried to run the script from the link you've sent, but it returns an error.

 

Nonetheless, I've extracted the SAS data types of the columns from my data set:

 

NameTypeLengthFormatInformatLabel
customerIDNumeric811.11. 
registrationDateDate8DDMMYY8.  
firstPurchaseDateDate8DDMMYY8.  

 

Besides that, I made an extraction with 1000 random observations and attached it to the post.

 

Thanks!

PaigeMiller
Diamond | Level 26

So, the INTCK function determines how many months, and PROC FREQ computes the number.

 

data have2;
    set have;
    months=intck('month',registrationdate,firstpurchasedate);
run;
proc freq data=have2;
    tables registrationdate*months/noprint list out=_counts_;
run;
--
Paige Miller
Renan_Crepaldi
Obsidian | Level 7
It worked!

Thank you very much, Paige.

Best regards,
Renan

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 693 views
  • 1 like
  • 2 in conversation