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!!

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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