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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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