Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting most occuring data....HELP!

Status
Not open for further replies.

MattSokol

Technical User
Jul 26, 2006
2
US
I have this data set of ZIP Codes. How would I display the top 2 occuring zip codes. For example, say the data set was:

12345
12345
12345
23444
23444
23444
78229
23525
23554
34667
23667
26775

The top two occuring Zip Codes are 12345 and 23444, because, well, they occur the most.

Actually my data set is over 1000 zip codes and I want to do the top 5, but once I see a sample I am sure I can get it. I was trying to this in my PROC FREQ step, but I can't get it to work. Any help would be great!!

THANKS!

-Matt
 
try proc freq with an output to a dataset.

Assuming that you have a dataset with a variable named ZIP.

Code:
proc freq data =your_data;
tables ZIP /out=freqcnt;
run;
proc sort 
  data = freqcnt
  out  = freqsort ;
  by descending count;
run;
data top5;
  set freqsort;
  if _n_ le 5; *** RETURNS THE TOP 5 ZIP CODES ***;
run;
proc print data =top5;
run;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top