title: How do I do frequency counts in a SAS DATA step?
body: <p>Learning SAS here... </p>
  
  <p>I have a data set, called <code>salesPeople</code> that looks like this:</p>
  
  <pre><code>personID      personZip
  123           47382
  123           47382
  123           47382
  123           47382
  123           47382
  123           47382
  123           47382
  123           47382
  123           76737
  123           76737
  123           76737
  123           Smallville
  123           Smallville
  123           Smallville
  654           27767
  654           27767
  654           27767
  654           27767
  654           27767
  654           27767
  654           27767
  654           83764
  654           83764
  654           83764
  654           83764
  654           Metropolis
  654           Metropolis
  654           Metropolis
  654           Metropolis
  ...           ...
  </code></pre>
  
  <p>For each <code>personID</code>, there may be up to several hundred observations. The vast majority of them will be in the same zip code. There may be 1-3 other valid zip codes. And, for each person, there are several observations that will have the city name (for example, Smallville) instead of the city zip (47382, in this case, which is in Smallville). In this data set, the city name, when found in the <code>personZip</code> column, ALWAYS corresponds to the most frequent properly entered personZip. </p>
  
  <p>For the purposes of what I'm doing, it is safe to assume that it would be fine to replace all instances of the city name with the most common <code>personZip</code>. Here, for example, it would be perfectly acceptable to replace <code>Smallville</code> with <code>47382</code> and <code>Metropolis</code> with <code>27767</code>. In fact, that is exactly what I want to do. There are several thousand unique <code>personID</code> values in the <code>salesPeople</code> data set, and several hundred thousand observations.</p>
  
  <p>What I want to do is to determine the most frequent <code>personZip</code> for each <code>personID</code> and then to replace the invalid city names with that zip. What is the best way to determine the most frequent <code>personZip</code> value and store it so that I can merge it back with the <code>salesPeople</code> data set?</p>