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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 546 views
  • 1 like
  • 2 in conversation