DATA Step, Macro, Functions and more

Counting the number of items within same date

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Counting the number of items within same date

Hi guys,

I am working on a dataset with participants having multiple rows. 

I want to know if any participant have used a specific medicare item number more than once in a same day. For example participant T10002 have used "36" twice in the same date (3rd and 4th rows). 

 

4.JPGThanks mates


Accepted Solutions
Solution
2 weeks ago
Valued Guide
Posts: 530

Re: Counting the number of items within same date

[ Edited ]

In SQL (there are other ways) this would be:

 

proc sql;
   select participant_id, medicare_item_number, date_of_service, count(date_of_service)
   from have
   group by participant_id, medicare_item_number, date_of_service
   having count(date_of_service) > 1;

quit;

Hope this helps,- Jan.

View solution in original post


All Replies
Solution
2 weeks ago
Valued Guide
Posts: 530

Re: Counting the number of items within same date

[ Edited ]

In SQL (there are other ways) this would be:

 

proc sql;
   select participant_id, medicare_item_number, date_of_service, count(date_of_service)
   from have
   group by participant_id, medicare_item_number, date_of_service
   having count(date_of_service) > 1;

quit;

Hope this helps,- Jan.

Occasional Contributor
Posts: 14

Re: Counting the number of items within same date

Posted in reply to jklaverstijn

Thanks

Contributor
Posts: 22

Re: Counting the number of items within same date

How about

data test;
    input subject$ med item$ date$;
    datalines;
    T10002 23 A1 8/3/2009
    T10002 23 A1 10/26/2009
    T10002 36 A1 12/9/2009
    T10002 36 A1 12/9/2009
    T10002 110 A4 12/16/2009
    T10002 116 A4 1/12/2009
    ;
run;
proc sort data=test out=test_1;
    by subject item date;
run;
proc freq data=test_1 noprint;
    tables med / out=cnt;
    by subject item date;
run;
Super User
Posts: 13,072

Re: Counting the number of items within same date

Do you want a data set, something that goes into other procedures for analysis, or a report for humans? Do want to see the counts of everything or only the cases where there are two or more of the item on the same date?

 

And are your "dates" actually SAS date values or just character variables that look like dates?

Occasional Contributor
Posts: 14

Re: Counting the number of items within same date

Thanks
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 129 views
  • 1 like
  • 4 in conversation