BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SasStatistics
Pyrite | Level 9

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ
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

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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) 

--
Paige Miller
sbxkoenk
SAS Super FREQ
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

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1393 views
  • 4 likes
  • 4 in conversation