BookmarkSubscribeRSS Feed
lamiaH
Obsidian | Level 7

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

6 REPLIES 6
Reeza
Super User

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;
lamiaH
Obsidian | Level 7
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
Reeza
Super User

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

 

lamiaH
Obsidian | Level 7
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,
ballardw
Super User

@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.

lamiaH
Obsidian | Level 7

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

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
  • 6 replies
  • 507 views
  • 2 likes
  • 3 in conversation