BookmarkSubscribeRSS Feed
Satori
Quartz | Level 8

I want to count the number of times each id appears in the whole dataset.

data example:

data have;
input id var1 var2;
datalines;
1	0	0
1	0	0
1	1	0
1	0	1
1	1	1
2	0	0
2	1	0
2	1	1
3	1	0
3	0	1
3	0	1
4	0	0
4	1	0
4	0	1
4	1	1
;
run;

 

What I want:

data want;
input id count;
datalines;
1	5
2	3
3	3
4	4
;
run;

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Counting is a job for PROC FREQ

 

proc freq data=have;
    tables id/noprint out=counts(keep=count id);
run;

 

 

--
Paige Miller
Satori
Quartz | Level 8
I did this, but the dataset hsa millions of observations so the dataset "counts" is huge and I cannot visualize it. Is there another way? My main goal is to know what is the frequency of the repetition of ids. So all the ids that appear once can be grouped, twice another group, etc.
PaigeMiller
Diamond | Level 26

Visualization was not mentioned in your original message. Visualization for what purpose? What type of visualization are you talking about ... please describe in more detail, or show us an example (perhaps from the Internet).

 

 

My main goal is to know what is the frequency of the repetition of ids. So all the ids that appear once can be grouped, twice another group, etc.

 

You could sort the output data set, which I named COUNTS, by the variable named COUNT.

--
Paige Miller
Satori
Quartz | Level 8
By visualize I meant look at the resulting table from the proc freq step.
PaigeMiller
Diamond | Level 26

Not really understanding here. You have millions of observations, you cannot look at them in any reasonably comprehensive way. You said:

 

My main goal is to know what is the frequency of the repetition of ids. So all the ids that appear once can be grouped, twice another group, etc.

And then I gave a suggestion on how to do this. If that doesn't work for you, DESCRIBE in a lot more detail what you want, or better yet, show us. Don't make me guess. Don't use words like "visualize" which means different things to different people and doesn't make sense to me in this situation.

--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 1148 views
  • 1 like
  • 3 in conversation