BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
danwarags
Obsidian | Level 7

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. 

 

IDsales
1car
1truck
1bike
1plane
2bike
2car
2motor
4plane
4bike
4car
4motor

 

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. 

 

NsalesNindividuals
10
20
31
42

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

2 REPLIES 2
Reeza
Super User

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;

PGStats
Opal | Level 21

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;
PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 2957 views
  • 3 likes
  • 3 in conversation