I'm working with a team for the upcoming season, and have been tasked with compiling statistics tracking data after every session (training and/or game), and creating cumulative variables based on the data. In addition to creating the cumulative variables, I need to append the relevant variables from the previous 3 sessions that each player has attended, in order to track progression. The variables that I need to keep from each sessions are called : Distance, Sprint_Distance & Top_Speed. The session data is extracted in CSV format for any player that has attended, and I append each sessions data to a master session dataset, which I need to be in order to create a count of how many sessions each player has attended. When reading in the session data, I append a numeric value to the end of each field, which indicates the session number. So session 1 will have field names: Distance_1 Sprint_Distance_1 Top_Speed_1 Session 2 will have '_2' appended at the end, session 3 has '_3' appended and so on for each subsequent session. While I've created the cumulative variables using the MEAN function, I'm having trouble extracting the data from the previous 3 sessions for each player. What I've tried is the following, extracting the last record and then deleting it so the next step will not extract the same record. data previous1 sessions1; set path.raw_session_data; by Player_Name; if last.Player_Name then output previous1; if last.Player_Name then delete; output sessions1; run; data previous2 sessions2; set sessions1; by Player_Name; if last.Player_Name then output previous2; if last.Player_Name then delete; output sessions2; run; data previous3 sessions3; set sessions2; by Player_Name; if last.Player_Name then output previous3; if last.Player_Name then delete; output sessions3; run; data prev_sessions; merge previous1 previous2 previous3; by Player_Name; run; What I'm looking to do is to keep only the variables where data is available when identifying the last 3 sessions attended, instead of appending all session variables to each of the previous1-3 datasets being created. The problem is that I don't know the variable names that will be extracted, as players won't have attended every session so far. For example, player 1 has attended sessions 1, 2, 4 and 6, player 2 has attended sessions 1, 3, 5 and 6, player 3 has attended all sessions 1, 2, 3, 4, 5, 6 etc. so these numbers will be appended to the variable names as outlined previously. I will then need to rename the variables to something like : Previous_Distance_1 for the most recent previous session; Previous_Distance_2 for the second most recent previous session; Previous_Distance_3 for the third most recent previous session; Hopefully I'm making sense!! Any help will be greatly appreciated!!
... View more