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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.