Hi, I have data with number of hours worked and county FIPS code. There are 3214 observations, and I want to add all the hours worked together for each county.
data ctyhoursworked1;
set data;
keep hoursworked CountyC1;
run;
proc sort data=ctyhoursworked1 out=ctyhoursworked2 nodupkey;
by CountyC1;
run;This gives me the number of observations in each county but does not add each observation value together. CSV file from the first command is attached.
Get rid of NODUPKEY. It will remove some observations, and you need all of the observations to add up the HOURSWORKED values.
Actually get rid of the entire PROC SORT. It isn't needed to add up numbers. Here's a possibility:
proc summary data=have nway;
var hoursworked;
class CountyC1;
output out=want (keep=CountyC1 total_hoursworked) sum=total_hoursworked;
run;
I think you are after proc means/summary/sql
Get rid of NODUPKEY. It will remove some observations, and you need all of the observations to add up the HOURSWORKED values.
Actually get rid of the entire PROC SORT. It isn't needed to add up numbers. Here's a possibility:
proc summary data=have nway;
var hoursworked;
class CountyC1;
output out=want (keep=CountyC1 total_hoursworked) sum=total_hoursworked;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.