BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi i have 5 variable i want the count of most observation occured

a b c d e most_obs count
1 1 1 2 3 1 3
5 5 6 5 2 5 2
9 9 2 0 8 2 9

in this first observation the mostly repedatd observation was 1 so the variable as most_obs as 1 and the count was 3 .like this i have 20,000 obs
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Using a DATA step and two arrays (one to track the values and another to track the counts), you can loop through each observation's variable "values" for A through E identifying each unique instance and incrementing a counter.

Scott Barry
SBBWorks, Inc.
Peter_C
Rhodochrosite | Level 12
might also find CALL SORTc/n() useful, to put the array values into order. Then as you go through the array of values, you only need to keep the latest value, it's counter and the highest value/count so far. It scales up better, and you won't need to search for the counter to update as you look at each (disordered) array value.

Peter
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
A SAS pre-processing SORT step gets the data into order, followed by the DATA step suggested. The use of two ARRAYs (in parallel, one for value and another for count) addresses the objective, using the DO I=1 TO DIM(); / END; with the "I" variable paralleling the two arrays.

Scott Barry
SBBWorks, Inc.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1418 views
  • 0 likes
  • 3 in conversation