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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.