Hi,
I am pretty new in using SAS and could use some help with the following problem.
I have data similar to this:
Code | value
1111 | 1
1111 | 2
1111 | 3
1111 | 4
1111 | 5
1112 | 1
1113 | 1
1113 | 2
1113 | 3
1113 | 4
1121 | 1
1121 | 2
1121 | 3
1121 | 4
1121 | 5
What do I want to do?
I want to calculate the mean and median of "value", iff "code" occurs 5 or more times in the table.
So, for example, I want SAS to check if the code "1111" exists 5 or more times. If yes, SAS should create new variables "median" and "mean" giving me the median and mean of the values of "1111" in a new file. Accordingly, "mean" and "median" in this case should be equal to 3:
Code | Median | Mean
1111 | 3 | 3
Now, SAS should do the same for "1112" and realize that there is only 1 observation. In this case, SAS should return "." and instead use all observations with the first three digits to calculate mean and median, so for all observations of code starting with "111" (1111, 1112, ..., 1118, 1119).
Code | Median | Mean
1111 | 3 | 3
1112 | . | .
111 | 2.5 | 2.6
And so forth...
Can anybody help me? I am pretty clueless at the moment...
Thanks a lot!
Tucker