title: SAS: Create a frequency variable
body: <p>I need to create a frequency in variable, not a proc freq output but an actual variable within the dataset. I used the below code create a running count by ID.</p>
  
  <pre><code> data work.frequencycounts;
   set work.dataset;
   count+1;
   by id;
   if first.id then count=1;
   run;
  </code></pre>
  
  <p>However, the variable I want is not a running count, it is the final count.  I tried to add </p>
  
  <pre><code> frequency=last.count;
  </code></pre>
  
  <p>to the end of the data step but that did not work.</p>