I have data of the following form:
Customer_ID | year_month | Segment |
1 | 202201 | A |
2 | 202201 | A |
3 | 202201 | B |
4 | 202201 | C |
5 | 202202 | A |
6 | 202202 | B |
7 | 202202 | B |
8 | 202202 | C |
9 | 202202 | B |
As you can see, we have different customer_id with different year_month and Segment values. Now I would like to count the number of customers for each unique combination or year_month and Segment.
The result should be as follows:
Segment | ||||
yearmonth | A | B | C | Total number |
202201 | 2 | 1 | 1 | 4 |
202202 | 1 | 3 | 1 | 5 |
Any ideas on how to do this in SAS?
data have;
input Customer_ID $ year_month $ Segment $;
datalines;
1 202201 A
2 202201 A
3 202201 B
4 202201 C
5 202202 A
6 202202 B
7 202202 B
8 202202 C
9 202202 B
;
run;
PROC FREQ data=have;
tables year_month * Segment;
run;
/* end of program */
Koen
UNTESTED CODE
proc freq data=have;
tables year_month*segment;
run;
(Please provide data as working SAS data step code from now on, so I can test the code I write against your data)
data have;
input Customer_ID $ year_month $ Segment $;
datalines;
1 202201 A
2 202201 A
3 202201 B
4 202201 C
5 202202 A
6 202202 B
7 202202 B
8 202202 C
9 202202 B
;
run;
PROC FREQ data=have;
tables year_month * Segment;
run;
/* end of program */
Koen
Hello @SasStatistics , it appears that @sbxkoenk has turned your data into SAS data step code. Good for him. Please do that yourself from now on, please do not provide data any other way.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: