BookmarkSubscribeRSS Feed
kcmitche
Calcite | Level 5

Good evening. I've got a question, obviously

 

 

i have a large data set (120k observation )

i need to find a way to count the number of times an event occurs after another ever 

 

example

 

evrytime there is a rows in my data is labeled with "O" in a colum, I need to count how many time the row directly below equals "2FGA" 

 

there is another column that represents a name with each row. 

If anyone knows how it would be possible to count how many time name associated with the "O" was counted would be great. 

 

Thanks for the help

 

ask me questoins if im being too broad. 

10 REPLIES 10
art297
Opal | Level 21

Not sure if I understand what you have but, hopefully, the following comes close:

 

data have;
  length event $4;
  set sashelp.class (keep=name);
  if _n_ in (2,4,6,8,10,12,14,16,18) then event='O';
  if _n_ in (3,7,11,13,17,19) then event='2FGA';
run;

data want (drop=last);
  set have;
  last=lag(event);
  if event='2FGA' and last eq 'O' then output;
run;

The resulting file, want, has 6 records which is the count I think you are looking for.

 

Art, CEO, AnalystFinder.com

 

kcmitche
Calcite | Level 5

I'll give it a try but to try and make myself more clear i'm attaching an example of the data.

 

So you'll see 5 columns

 

1st (no title) / 2nd (team_name) / 3rd (player_name) / 4th (event_desc_id) / 5th (event_desc)

 

so basically there will be values in the 'event_desc_id' column such as 2FGAB, AG, FV, D, O, 3FGA, 2FGA

I would like to count the number of times that the row directly after an 'O' has a '3FGA' or a 2FGA'

 

hopefully that will make a bit more sense 

 

art297
Opal | Level 21

Did you try the method I suggested? To repeat, :

 

data want (drop=last);
  set have;
  last=lag(event);
  if event in ('2FGA','3FGA') and last eq 'O' then output;
run;
kcmitche
Calcite | Level 5

When I run the results nothing pops up it does straight to the output tab

kcmitche
Calcite | Level 5

i couldn't figure it out with the code you suggested.  Sorry i'm still new to sas.

All i did was import the data and then followed with what you wrote but clearly that wasn't correct.

art297
Opal | Level 21

post the code you ran

kcmitche
Calcite | Level 5

so far this is all i have. 

 

 

proc import datafile="/home/kcmitche/DataChallengeEuroGamePBP-2.csv"
out=EuroBB dbms=csv replace;
run;

data want (drop=last);
set have;
last=lag(event);
if event in ('2FGA','3FGA') and last eq 'O' then output;
run;

 

 

again rookie here

art297
Opal | Level 21

And, can you view file WANT? If I correctly understand what you wanted, the number of records in that file is the answer you were seeking.

 

Art, CEO, AnalystFinder.com

 

kcmitche
Calcite | Level 5

So I'm trying to count the number of times that a selected variables happen directly after an 'O'.  

 

For example in the sample data.

row 25 has 'O' and directly below that row 26 has a '2FGA'

 

I want to find a way to show how many times that the player_name associated with an 'O' resulted in a 2FGA or 3FGA directly after the 'O'.  I don't care about the player_name in the following row or in the row with 'O'

 

 

try and explain differently

in row 25. 

Honeycutt, Tyler = 1 'O' (because directly after there was a 2FGA

 

next would be 

Rice, Tyrese (row 29)

he would = 1 because there was a 3FGM after.

 

does that make more sense.

 

kcmitche
Calcite | Level 5

I'd like to make a table showing me how many times this happened to each player.

'O' stands for offensive rebounds.

 

Basically i would like to find a way to find the top 5 players whose offensive rebounds resulted in an attempted shot on the basket

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 5820 views
  • 0 likes
  • 2 in conversation