BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PKERR85
Calcite | Level 5

Hi guys,

 

I am looking to create a player database to count number of appearances by players over a period of time.

 

For example

 

Match  Player 1   Player 2  Player 3   Player 4  Player 5

1           Smith         Jones        Brown        Thomas     Kerr

2           Smith         Jones        Brown        Thomas     Kerr

3           Smith         Jones        Brown        Thomas     Kerr

4           Smith         Jones        Brown        Thomas     Kerr

5           Smith         Kerr           Brown        Thomas     Phillips

 

So for instance Kerr has made 5 appearances but in different positions whereas Jones has made 4 appearances all in the same position. I want to be able to loop through each position ( 5 in this scenario) to check how many appearances each person has made.

 

Any help would be appreciated.

 

Thanks, Paul

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

My mistake it should say

 

player=p(i);
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

I would stack the positions into one, and then count.

 

data stacked;
    set have;
    array p player1-player5;
    do i=1 to dim(p);
         player=player(i);
         output;
    end;
    drop player1-player5;
run;
proc freq data=stacked;
    table player/out=_counts_;
run;
--
Paige Miller
PKERR85
Calcite | Level 5
Thanks for the quick response Paige. Seem to be getting the below error.

22 data stacked;
23 set gw_stat_v2;
24 array p player1-player23;
25 do i=1 to dim(p);
26 player=player(i);
______
68
ERROR 68-185: The function PLAYER is unknown, or cannot be accessed.
PaigeMiller
Diamond | Level 26

My mistake it should say

 

player=p(i);
--
Paige Miller
novinosrin
Tourmaline | Level 20

HI @PKERR85  same idea with a proc transpose

 

data have;
input Match  (Player1   Player2  Player3   Player4  Player5) (:$32.);
cards;
1           Smith         Jones        Brown        Thomas     Kerr
2           Smith         Jones        Brown        Thomas     Kerr
3           Smith         Jones        Brown        Thomas     Kerr
4           Smith         Jones        Brown        Thomas     Kerr
5           Smith         Kerr           Brown        Thomas     Phillips
;

proc transpose data=have out=temp(keep=col1 rename=col1=player);
by match;
var player1-player5;
run;
proc freq data=temp;
    table player/out=want;
run;
PKERR85
Calcite | Level 5

Thanks guys much appreciated

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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