BookmarkSubscribeRSS Feed
JFranco2
Calcite | Level 5

I would like to see who uses something most.  I have a column of the product and I have a column of the user ID - I want to only know who is using it most.  The Data Set shows every time the product is used and by whom - I want to use those two columns to calculate one or two new columns (I also have the date) so a column to show the count of the most times used. Any suggestions?

7 REPLIES 7
JFranco2
Calcite | Level 5

I know I can do this in a summary table but want to remove the duplicates entries and only keep the highest frequency information

Tom
Super User Tom
Super User

Perhaps the COUNT() aggregate function of PROC SQL with the DISTINCT keyword to eliminate duplicates?

proc sql;
create table want as
  select groupvar , count(distinct entryvar) as n_entries
  from have
  group by groupvar
  order by n_entries desc 
;
quit;
PaigeMiller
Diamond | Level 26

... to calculate one or two new columns ...

 

This is pretty vague. What should those one or two new columns contain? Will they be in the same data set or a new data set? How do they relate to measuring highest frequency?

 

Could we measure highest frequency without creating one or two new columns?


Given your explanation above, it seems like just counting isn't the way you want to get to "highest frequency". Could you elaborate on what you mean by "highest frequency"?

--
Paige Miller
JFranco2
Calcite | Level 5

Actually I think it is just one column.

 

Column: would have the occurrence ascending by date order.  So for instance if I used two vehicles 101 times over the course of a year the new column (using vehicle number, my personal ID number and date columns) would show numbers going from 1-what ever the count is for each vehicle.

PaigeMiller
Diamond | Level 26

Maybe this?

 

proc sort data=have;
    by vehicle_number ID date;
run;

data want;
    set have;
    by vehicle_number id;
    if first.id then count=0;
    count+1;
run;
--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 7 replies
  • 1053 views
  • 0 likes
  • 3 in conversation