03-29-2013 01:07 PM
So I have some data which has different players assigned to different clusters, along with a do loop for each one of the clusters which is stored in the macro language. So basically, right now, I have a do loop which says "do the following from 1 to C" where C is the macro number (ranges from 1 to 8.)
Then I want to add up the number of times a player appears in the particular cluster, and also how many times they appear overall. So the following code is a basis. I cant just look at the observations in C because then I wouldnt know how many times a player would appear total. I dont know how to use a first. in a similar fashion when the cluster number will change (the variable cluster will vary for each player. So lets say when a player is at home, he is in cluster 4, and when he goes on the road he might appear in cluster 5 and so on. So I cant actually use the code as it is now).
Does this make sense? Any ideas?
|by player_id cluster game_date;|
|if first.cluster then numcluster=0;|
|if first.player_id then numtotal=0;|
03-29-2013 01:37 PM
And so forth.So lets say for cluster 2, I only want the player for the obs. in cluster 2, the last observation would have numcluster to be 4 and numtotal to be 7. Numcluster will only increase when cluster = C (the particular iteration of the do loop.) so at C=1, numcluster gets added by 1.
I am trying to get it to do if cluster=&&C then numcluster+1 but it doesnt seem to work.
03-29-2013 02:05 PM
I should add the do loop looks like this:
%do C=1 %to &Num_Clusters;
and then Num_Clusters is found in the macro call with a value of 8.
03-29-2013 09:29 PM
Not clear at all.
On the one hand it sounds like you want to GENERATE data based on some macro variable. If that is the case write a date step. You should be able to write the data step using data step DO looping and just set the bounds of the loops using the macro variables.
do c= 1 to &num_clusters;
On the other hand it sounds like you want to summarize some existing data and group by variables in the data. In that case use PROC SUMMARY or possible PROC TABULATE.