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

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  
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Moraes86
Obsidian | Level 7
Thank you very much PaigeMiller!
It worked!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 896 views
  • 1 like
  • 2 in conversation