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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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