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

I am working on a nationwide dataset where has my outcome variable at both county and state level. ealier I used PROC SQL  and group by statement to get a total deaths by state and here is my code: 

proc sql;
create table test1 as select *, count(*) as total_deaths from aggregatedallv1 group by State_Occurrence_FIPS  quit;

this gave me a columns as total per State. Now I wonder how to get total per county group by State. 

any advice is much appreciated. 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Assuming that in your source table HAVE you've got one row per death and you've got a variable for state and one for county then code along the line of below should work.

proc sql;
  create table test1 as 
    select 
      state
      ,county 
      ,count(*) as total_deaths 
    from have 
    group by state, county
  ;
quit;

If you want to get aggregated values (count, sum, ...) on different level (like state and state,county) using a single Proc then look into Proc Means.

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

Assuming that in your source table HAVE you've got one row per death and you've got a variable for state and one for county then code along the line of below should work.

proc sql;
  create table test1 as 
    select 
      state
      ,county 
      ,count(*) as total_deaths 
    from have 
    group by state, county
  ;
quit;

If you want to get aggregated values (count, sum, ...) on different level (like state and state,county) using a single Proc then look into Proc Means.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 1037 views
  • 1 like
  • 2 in conversation