07-02-2015 10:22 PM
I currently have a table that outputs top 3 servicing providers referred to by a given provider in the following fashion:
What I'm hoping for is a table more like the following:
|Provider||Top Servicer||Top Percent||Second Servicer||Second Percent||Thrid Servicer||Third Percent|
How can I do this?
07-03-2015 08:54 AM
The simplest way is using proc means + idgroup .
Or you could try the MERGE skill me,Matt,Arthur.T have talked about it at :
input provider $ service $ percent $;
p1 s1 1
p1 s2 2
p1 s3 3
p2 s1 1
p2 s2 2
select max(count) into : n
from (select count(*) as count from have group by provider );
proc summary data=have ;
output out=want idgroup(out[&n] (service percent)=);
07-03-2015 05:01 PM
I forgot that for some of the providers there aren't 3 providers that have been referred to (e.g. one provider may have only every referred to themselves and one other clinic, or maybe they'd have only "referred" to themselves). Will this make a difference with respect to the code you've posted, or would it have to modified?
07-03-2015 05:22 PM
What you're looking for is a Transpose.
Most solutions deal with the fact that there are less than the maximum number.
07-03-2015 09:56 PM
No problem . proc mean + idgroup can handle the variety number of patient.
But you need pick up these 3 largest obs firstly .
Message was edited by: xia keshan
07-10-2015 11:13 AM
Thanks for the replies.
I ended up using the following code:
SET work.top_3_allwd_a; By year attributed_tin_nm_rllp;
* Tells SAS not to reset these variables to
missing when going to top of datastep;
FORMAT first second third $CHAR105.;
RETAIN first second third percent1 percent2 percent3;
* Set variables to missing when reading new
member - clear previous member's data!;
if FIRST.attributed_tin_nm_rllp = 1 then do;
first=''; second=''; third='';
percent1=.; percent2=.; percent3=.;
if count = 1 then do ;
first = prov_name_serv; percent1= percent_of_allwd;
if count = 2 then do ;
second = prov_name_serv; percent2= percent_of_allwd;
if count = 3 then do ;
third = prov_name_serv; percent3= percent_of_allwd;
* Output variables only when done with member;
if LAST.attributed_tin_nm_rllp = 1 then OUTPUT;
KEEP year attributed_tin_nm_rllp first second third percent1 percent2 percent3;
07-10-2015 01:27 PM
PROC SUMMARY with IDGROUP can be used to find the top three servicers(name) for any given variable(weight) and output the results in wide format.