calculating counts of tests for months and years

Reply
Contributor
Posts: 27

calculating counts of tests for months and years

Hello, 

 

I want an advice on the best way to calculate counts of testing for each month/year.

So my data looks as below. I want the count of testing for each month.year. 

 

 

Patient  tests  service date

1            1        31Jan1992

1             1       23Jul1995

2            1         04Feb1992

 

I want to calculate the testing count for each month in each year, so I have count for Jan, 1992 and for Feb 1992, till the latest record for 2015. the same patient may have different testing at different dates.

Can I sort by date first and then make a do loop of first. service date and last.service and make the sum of testing. ? Any advice how best to tackle this? 

Thank you so much, looking forward to hear back from you. 

 

Best,

Lamia

Super User
Posts: 23,224

Re: calculating counts of tests for months and years

Do you have duplicates you ned to account for? If not, then you can use PROC FREQ?

 

proc freq data=have;
format service_date yymon7.;
table service_date / out= want;
run;
Contributor
Posts: 27

Re: calculating counts of tests for months and years

Thank you so much for your reply. I will try this, but I need the counts to
be within the data and not a result and for every month/year. I want to use
them later in another step. Would this work?

Thanks
Super User
Posts: 23,224

Re: calculating counts of tests for months and years

You can merge them back in, or if you want them directly in you could probably use SQL. 

Note that you didn't state that initially so I'm going to leave that step up to you.

 


lamiaH wrote:
Thank you so much for your reply. I will try this, but I need the counts to
be within the data and not a result and for every month/year. I want to use
them later in another step. Would this work?

Thanks

 

Contributor
Posts: 27

Re: calculating counts of tests for months and years

Hi Reeza,

Thanks for replying again, I've tried your code and it worked very nicely.
Sorry, I have should stated that I needed the counts. I have another
question for time later, but will ask it later when I will do the analysis
of time series.


Thanks for your help,
Super User
Posts: 13,286

Re: calculating counts of tests for months and years


lamiaH wrote:
Thank you so much for your reply. I will try this, but I need the counts to
be within the data and not a result and for every month/year. I want to use
them later in another step. Would this work?

Thanks

You may want to provide a few more lines of example data and then what the resulting data set you want would look like at the end for those given values.

Contributor
Posts: 27

Re: calculating counts of tests for months and years

Hi again, 

 

So inorder to put this formate within the data , I 've created a nother date variable and 

 

 

date=servdate;

format date yymon7.;

run;

so it gave me this format within the same data. 

 

Thanks again

Lamia

Ask a Question
Discussion stats
  • 6 replies
  • 176 views
  • 2 likes
  • 3 in conversation