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.
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.