Hello good morning, I could not find the way to do the following, I have an ID and a date of a certain event. I must add the difference in months of an event with the following one by ID.
Example in excel in the photograph.
someone who can help me, Greetings.
And so what is the desired result? Do you want 9 for ID = 1 and 12 for ID = 2 and 12 for ID=3?
Is your date variable a character variable in SAS or a numeric variable in SAS? What does PROC CONTENTS say?
FYI, please do not provide data as screen captures from Excel. The preferred method to provide data is:
https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/
That's Excel, not SAS data shown. In the future please show the SAS version. I'm assuming you have your data imported and that your date are SAS dates, eg numeric with a date format.
proc sort data=have;
by ID;
run;
data want;
set have;
by ID;
prev_date = lag(date);
if not first.id then n_month = intck('month', date, prev_date, 'C');
run;
You may need to play with the INTCK() function to get the exact numbers you want but this gives you an idea of how to do it.
@Andres_Fuentes1 wrote:
Hello good morning, I could not find the way to do the following, I have an ID and a date of a certain event. I must add the difference in months of an event with the following one by ID.
Example in excel in the photograph.
someone who can help me, Greetings.
Nice, Thanks you.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.