BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jesspurse
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

I think you are after proc means/summary/sql

Astounding
PROC Star

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;

jesspurse
Obsidian | Level 7
Thanks! This worked perfectly.
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1520 views
  • 0 likes
  • 3 in conversation