SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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