BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mary_mcneill
Obsidian | Level 7

Hello, I am looking to get monthly counts by a variable Region as well as the monthly counts for each county within that region. I have tried to use proc summary to do this; however, it will provide 0 values for all the counties  for every region and not just the counties within each Region. Is there a way to limit the county variable to only include the counties within each region as well as a total count for the region? 

 

Preferable output:

Region

County

1 - Jan

2 - Feb

3 - Mar

Region 1

County A

0

0

0

Region 1

County M

5

4

7

Region 1

County F

0

2

1

Region 1

County Z

12

20

17

Total Region 1

 

17

26

25

Region 2

County N

0

0

0

Region 2

County G

1

0

2

Region 2

County P

3

1

0

Total Region 2

 

4

1

2

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

When you want a specific formatting of a table, PROC REPORT seems like a better way to get there.

 

proc report data=mydata;
	columns region county month;
	define region/group "Region";
	define county/group "County";
	define month/across "Month";
run;
--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

Please show us the input data.

--
Paige Miller
mary_mcneill
Obsidian | Level 7

data mydata;

  infile datalines;

  input county month region ;

return;

datalines;

M 1 1

M 1 1

M 1 1

M 1 1

M 1 1

M 2 1

M 2 1

M 2 1

M 2 1

M 3 1

M 3 1

M 3 1

M 3 1

M 3 1

M 3 1

M 3 1

F 2 1

F 2 1

F 3 1 

G 1 2

G 3 2

G 3 2

P 1 2

P 1 2

P 1 2

P 2 2

;

run;

mary_mcneill
Obsidian | Level 7

Sorry I forgot to designate my character variable. I also excluded County Z due to volume.

 

data mydata;

  infile datalines;

  input county $ month region ;

return;

datalines;

M 1 1

M 1 1

M 1 1

M 1 1

M 1 1

M 2 1

M 2 1

M 2 1

M 2 1

M 3 1

M 3 1

M 3 1

M 3 1

M 3 1

M 3 1

M 3 1

F 2 1

F 2 1

F 3 1 

G 1 2

G 3 2

G 3 2

P 1 2

P 1 2

P 1 2

P 2 2

;

run;

PaigeMiller
Diamond | Level 26

When you want a specific formatting of a table, PROC REPORT seems like a better way to get there.

 

proc report data=mydata;
	columns region county month;
	define region/group "Region";
	define county/group "County";
	define month/across "Month";
run;
--
Paige Miller
mary_mcneill
Obsidian | Level 7

Hi Paige,

 

Thanks that works! Do you know how I would get a total region count (total Region1, total region2) as well as any county within the region to display that did not have any values (i.e. Region1 CountyA, Region2 CountyN). Perhaps this would have to be done in a format?

PaigeMiller
Diamond | Level 26
proc report data=mydata;
	columns region county month;
	define region/group "Region";
	define county/group "County";
	define month/across "Month" format=mon. order=internal;
	break after region/summarize;
run;

Naturally, this can be formatted a little nicer, but that's what I got right now.

--
Paige Miller
JeanDo
Obsidian | Level 7

Hello,

I think exactly the same way, Paige, and will propose the same solution with the sum by region:

 

proc report data=mydata ;
column region county month;
define region / group;
define county /group;
define month / across;
break after region /summarize;
run;

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
  • 7 replies
  • 774 views
  • 0 likes
  • 3 in conversation