From: Sdlentertd on 5 Mar 2010 13:36 I have this dataset State Color count_var AZ red 10 AZ green 2 CA red 5 CA yellow 8 I need to rank each color for each state and add % of count_var they had in that state so the outcome will be Color State Rank % of count_var Red AZ 1 .833 Red CA 2 .385 green AZ 2 .167 yellow CA 1 .615 The ranking part is proc summary = have nway missing class state color; var count_var; output out = file1 sum = ; run; proc rank data = file1 out = file2 descending ties = low; by state; var count_var; run; How do I do the percentage field? (Percent of count_var each color had in each state where they had presense) Thank you
From: Joe Matise on 5 Mar 2010 14:34 PROC TABULATE might be the easier way to do this [or, in a data step]. That allows you to use PERCENTN and such. -Joe On Fri, Mar 5, 2010 at 12:36 PM, Sdlentertd <sdlentertd(a)gmail.com> wrote: > I have this dataset > State Color count_var > AZ red 10 > AZ green 2 > CA red 5 > CA yellow 8 > > I need to rank each color for each state and add % of count_var they > had in that state > so the outcome will be > > Color State Rank % of count_var > Red AZ 1 .833 > Red CA 2 .385 > green AZ 2 .167 > yellow CA 1 .615 > > The ranking part is > proc summary = have nway missing > class state color; var count_var; > output out = file1 sum = ; > run; > proc rank data = file1 out = file2 descending ties = low; by state; > var count_var; run; > > How do I do the percentage field? (Percent of count_var each color had > in each state where they had presense) > > Thank you >
From: Sdlentertd on 5 Mar 2010 15:33 On Mar 5, 12:34 pm, snoopy...(a)GMAIL.COM (Joe Matise) wrote: > PROC TABULATE might be the easier way to do this [or, in a data step]. That > allows you to use PERCENTN and such. > > -Joe > > > > On Fri, Mar 5, 2010 at 12:36 PM, Sdlentertd <sdlente...(a)gmail.com> wrote: > > I have this dataset > > State Color count_var > > AZ red 10 > > AZ green 2 > > CA red 5 > > CA yellow 8 > > > I need to rank each color for each state and add % of count_var they > > had in that state > > so the outcome will be > > > Color State Rank % of count_var > > Red AZ 1 .833 > > Red CA 2 .385 > > green AZ 2 .167 > > yellow CA 1 .615 > > > The ranking part is > > proc summary = have nway missing > > class state color; var count_var; > > output out = file1 sum = ; > > run; > > proc rank data = file1 out = file2 descending ties = low; by state; > > var count_var; run; > > > How do I do the percentage field? (Percent of count_var each color had > > in each state where they had presense) > > > Thank you- Hide quoted text - > > - Show quoted text - I can't figure out how to code it in Proc Tabular here is what i have but it's obviously wrong proc tabulate data = have; class state color ; var count_var; table state* (sum = 'count_var'*f = comma10. pctsum<color > = '% of row' pctsum<state>='% of column' pctsum = '% of all'), state*color ; run;
From: PJ on 8 Mar 2010 09:04 Try this one to see if this is what you are looking for The SAS System 08:50 Monday, March 8, 2010 2 count_ Obs color state var perc 1 Red AZ 10 0.83333 2 Red CA 5 0.38462 3 green AZ 2 0.16667 4 yellow CA 8 0.61538 data have; input state $ color $ count_var; cards; AZ Red 10 AZ green 2 CA Red 5 CA yellow 8 ; proc sql; create table perc(drop=_tot) as select color,state, sum(count_var) as _tot, count_var, divide(count_var, calculated _tot) as perc from have group by state order by color, state; quit;
|
Pages: 1 Prev: Annotated Graph Problem Next: Return the name of the file currently open in the Enhanced |