The SAS Output Delivery System and reporting techniques

cummulative pct

Reply
Occasional Contributor
Posts: 17

cummulative pct

I am trying to output the top 80% of the values of a variable
across by groups.
Ex: top 80% of DRGs (by volume) across hospital service lines.
N/A
Posts: 0

Re: cumulative pct

The only tricky part of this process is getting the denominator for each by group and making that available to your unsummarised data. Since you are working with "by groups", then I'll assume your data are already ordered in group sequence. If it isn't, then sort the data first.

Then summarise the data so you get frequencies for each group. The Freq procedure is best for this approach and code like the following should suffice.

[pre]
Proc Freq Data = SERVICES;
By DRG / Output Out = DRGFREQ;
Run;
[/pre]

Now match merge your two tables using the DRG key. There will be a column called COUNT, which is the frequency of each DRG group. You can rename this on merging if a column of the same name already exists on your unsummarised data.

Now split your data with code like the following:

[pre]
Data TOP80
LAST20;
Set SERVICES;
By DRG;
If First.DRG Then GROUPFREQ = 0;
GROUPFREQ ++ 1;
If GROUPFREQ / COUNT <= 0.8 Then Output TOP80;
Else Output LAST20;
Run;
[/pre]

I don't have a sample of your data, or a structure so the code above is provided as an example only.

Good luck.
Ask a Question
Discussion stats
  • 1 reply
  • 126 views
  • 0 likes
  • 2 in conversation