Hi guys,
Suppose to have a dataset:
ID Class Place
1 0 1
2 0 1
3 0 1
4 1 2
5 2 2
6 2 2
..... ..... .....
Then, you have another dataset of which you will take only the total number of rows, for example 10.
Now you want to divide the number of IDs in the first dataset by the total number of IDs in the second dataset, i.e., 10 but you want to do this by "Class" and "Place". How, this, can be achieved? In other words the desired output would be:
Place | Class | Count | Ratio |
1 | 0 | 3 | 0.3 |
1 | 1 | 0 | 0 |
1 | 2 | 0 | 0 |
2 | 0 | 0 | 0 |
2 | 1 | 1 | 0.1 |
2 | 2 | 2 | 0.2 |
As you can see (as an example), for place =1, there are IDs only in Class 0 and they are 3 in total. So 3/10 = 0.3. These are example numbers of the real situation. Totally I have 10 "Classes", 1 "Place" and 19.398 rows in the first dataset and 76.984 rows in the second dataset.
Thank you in advance
For problems that involve counting, your first choice ought to be PROC FREQ
proc freq data=have;
tables class*place/noprint list sparse out=counts;
run;
data want;
set counts(drop=percent);
ratio=count/10;
run;
From now on, please provide data as WORKING data step code, for example:
data have;
input ID Class Place;
cards;
1 0 1
2 0 1
3 0 1
4 1 2
5 2 2
6 2 2
;
For problems that involve counting, your first choice ought to be PROC FREQ
proc freq data=have;
tables class*place/noprint list sparse out=counts;
run;
data want;
set counts(drop=percent);
ratio=count/10;
run;
From now on, please provide data as WORKING data step code, for example:
data have;
input ID Class Place;
cards;
1 0 1
2 0 1
3 0 1
4 1 2
5 2 2
6 2 2
;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.