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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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