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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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