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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.