DATA Step, Macro, Functions and more

Need help firguring out how to randomly select between obs. with certain conditions

Reply
Frequent Contributor
Posts: 82

Need help firguring out how to randomly select between obs. with certain conditions

So I have a macro that is creating a list of games a person is going to see during the year. Lets say the first game they will see is game 'A'. I then have another dataset that has all the players that play in game 'A'. For each of these players, I need to mark that I have seen these players so I decrease the number of times I still need to see them.

So here is the dataset with the players:

PlayerGameTeamTImes seenPosition
12ABBBPitcher
45ABBBOut fielder
84ACCC3rd baseman

So in game A, I could see all these players. But I need to choose if I see 'BBB's players or 'CCC's players, since I cant see players from opposing teams. so basically, if I see game A, I want to randomly select a player that I see, and then see all the other players on that team (so I would see player 12 and 45 if it randomly selects a player from that team, or just player 84 if it selects that player). Does this sound like it would need to be really complicated?

Right now, all I do is update times seen to be +1 if we see game A, and need to add this random and conditional element to it. How would you go about doing this?

Regular Contributor
Posts: 195

Re: Need help firguring out how to randomly select between obs. with certain conditions

Hello,

It is completely depands on How you randomly taking players...For Example, at first time you randomaly took player 12 and 45 then you can eassily automate the process but if at second time if you randomaly took player 84 then you have to think different logic so that you can update time seen variable...

In short, it is more on How you selects the Players...

I tried to make logic for this but i stuck on if user execute code different time, he or she will get different players each time...so...

it will be good if you post output you want and how you selects the players...

Thanks,

Urvish


Frequent Contributor
Posts: 82

Re: Need help firguring out how to randomly select between obs. with certain conditions

Posted in reply to UrvishShah

I am running this multiple times, so here it what it looks like.

A game is chosen, and outputs game 'A'. Then I use sql right now to change a variable called 'viewed' to 1 for each player in that game. Then total number of views is calculated for each player, then the algorithm chooses the next game, and I updated the views, and so forth.

So the algorithm ends up with a list of lets say 100 games (in one column), and then I have to look up that list, and update the views for the players in those 100 games.

I do want to randomly select which player I see based on game A. So we see game A, I want to randomly select one player I see. Then I can write code to mark other players in that game as seen based on some criteria I have. So it might randomly select player 12, then based on my criteria it would also mark player 45. Are you saying the problem is as it adds to the list, the randomly chosen player would change each time?

Regular Contributor
Posts: 195

Re: Need help firguring out how to randomly select between obs. with certain conditions

Ask a Question
Discussion stats
  • 3 replies
  • 207 views
  • 0 likes
  • 2 in conversation