Hi all,
I am wondering to count how many days an event occurred.
In this example, the interval between the first day and the last days is 20 days.
So, there are repeatable days; thus, I would like to know how many days this event occurs.
For example, in this case, it occurred in 10 days, even it was 20 days interval. Therefore, I wish to get this result: 10 days.
Thanks all
data want ;
set have; ;
by id date ; (I think it is right)
/* this part that I am not sure */
run;
HAVE | WANT | ||||
id | date | id | date | Number of days | |
A | 13-Sep-19 | A | 13-Sep-19 | 10 | |
A | 18-Sep-19 | A | 18-Sep-19 | ||
A | 18-Sep-19 | A | 18-Sep-19 | ||
A | 18-Sep-19 | A | 18-Sep-19 | ||
A | 18-Sep-19 | A | 18-Sep-19 | ||
A | 19-Sep-19 | A | 19-Sep-19 | ||
A | 19-Sep-19 | A | 19-Sep-19 | ||
A | 24-Sep-19 | A | 24-Sep-19 | ||
A | 25-Sep-19 | A | 25-Sep-19 | ||
A | 25-Sep-19 | A | 25-Sep-19 | ||
A | 25-Sep-19 | A | 25-Sep-19 | ||
A | 25-Sep-19 | A | 25-Sep-19 | ||
A | 25-Sep-19 | A | 25-Sep-19 | ||
A | 27-Sep-19 | A | 27-Sep-19 | ||
A | 27-Sep-19 | A | 27-Sep-19 | ||
A | 30-Sep-19 | A | 30-Sep-19 | ||
A | 30-Sep-19 | A | 30-Sep-19 | ||
A | 30-Sep-19 | A | 30-Sep-19 | ||
A | 1-Oct-19 | A | 1-Oct-19 | ||
A | 1-Oct-19 | A | 1-Oct-19 | ||
A | 2-Oct-19 | A | 2-Oct-19 | ||
A | 2-Oct-19 | A | 2-Oct-19 | ||
A | 2-Oct-19 | A | 2-Oct-19 | ||
A | 3-Oct-19 | A | 3-Oct-19 | ||
A | 3-Oct-19 | A | 3-Oct-19 |
Untested code
proc sql noprint;
select id,count(distinct date) from have
group by id;
quit;
From now on, please do not provide data as screen captures. We strongly prefer data provided as SAS data step code (instructions). This allows us to send you TESTED code, rather than untested code, which the above is.
Untested code
proc sql noprint;
select id,count(distinct date) from have
group by id;
quit;
From now on, please do not provide data as screen captures. We strongly prefer data provided as SAS data step code (instructions). This allows us to send you TESTED code, rather than untested code, which the above is.
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.