I have my data in the following format
Trip Person Fish
A John 2
A Dave 4
A Kim 3
B Brian 1
B Alison 2
I don't care about the Person. I care about the number of fish per trip. So I am trying to sum up all the total fish for each trip. So I am trying to get this converted into the following output:
Trip Fish
A 9
B 3
Any advice would be greatly appreciated. Thanks.
@elopomorph88 wrote:
That is helpful but I forgot another part of it.
Can you please take some time and give us a complete and clear description of the problem and the desired output?
I am trying to create a new dataset that has the sum of the total fish for each trip and also the new dataset includes other data variables from the dataset. Here is my example with more detail:
Trip Person Fish Date State
A John 2 May 1 NC
A Dave 4 May 1 NC
A Kim 3 May 1 NC
B Brian 1 May 10 GA
B Alison 2 May 10 GA
So I want to also have the Date and State data included in the new dataset.
Are date and state always the same for each Trip? Or can they vary within trip? These are the types of things we need to know, so we don't provide an answer, and then you come back again and say you left another thing out.
use the PROC MEANS code from @Reeza above, with the ID statement added
id date state;
If your goal is to add the total number of fish caught on a trip to the detailed data of the trip you can use PROC SQL and only group on trip. In that way the summary statistics are merged to the original data.
data catch;
infile datalines;
input trip $ person $ fish;
datalines;
A John 2
A Dave 4
A Kim 3
B Brian 1
B Alison 2
;
run;
proc sql;
create table catch_stats as
select trip, person, fish, sum(fish) as total_catch
from catch
group by trip
;
quit;
will produce a dataset with the total number of fish per trip added:
trip person fish total_catch
A Kim 3 9
A John 2 9
A Dave 4 9
B Alison 2 3
B Brian 1 3
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.