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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 352 views
  • 2 likes
  • 3 in conversation