- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello all,
I have a dataset with hundreds of observations. I wanted to know how many individual IDs had more than1 or 2 or 3.... sales. Here is my sample dataset.
ID | sales |
1 | car |
1 | truck |
1 | bike |
1 | plane |
2 | bike |
2 | car |
2 | motor |
4 | plane |
4 | bike |
4 | car |
4 | motor |
In the above dataset each Individual ID had either 4 sales (For 1st ID), 3 sales (For 2nd ID) or 4 sales (For 4th ID). I wanted to know how many individuals had 4 sale count and three sale count. My output should look something like this.
Nsales | Nindividuals |
1 | 0 |
2 | 0 |
3 | 1 |
4 | 2 |
There were no Subject IDs with 1 or 2 sales count. So the first two rows are zero. There was 1 subject ID (ID-2) with 3 sales and 2 subject IDs (ID-1 and 4) with 4 sales.
Thank you
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Double proc freq.
1. First one gets you a count by Person and Sales (table id).
2. Second one gets you how many of each types of sales and then you can filter out what you need.
You won't get 0's though, only missing so you'll need fo find a way to add them in, there's several.
proc freq data=sashelp.cars noprint;
table make/out=countID;
run;
proc freq data=countID;
table count/out=Want;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Double proc freq.
1. First one gets you a count by Person and Sales (table id).
2. Second one gets you how many of each types of sales and then you can filter out what you need.
You won't get 0's though, only missing so you'll need fo find a way to add them in, there's several.
proc freq data=sashelp.cars noprint;
table make/out=countID;
run;
proc freq data=countID;
table count/out=Want;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Or use a SQL query:
proc sql;
create table salesCount as
select nSales, count(id) as nIndividuals
from (
select id, count(sales) as nSales from have group by id)
group by nSales;
select * from salesCount;
quit;