BookmarkSubscribeRSS Feed
ahappel
Calcite | Level 5
Hello,
I know this is simple but I'm a new grad student and trying to get this to work.

I have data formatted like this:
LOC FISHID PREY AMT
1 1 1 3
1 1 2 30
1 1 3 9
1 1 4 12
1 2 4 6
1 2 6 1

I would like to combine the totals for things like prey items 2 and 3 into one total named something like "worms". And then say name prey items 4 through 11 "fish" and so on.
1 1 beetles 3
1 1 Worms 39
1 1 fish 3
1 2 fish 7


The format for the names would need to be kept as later in the coding i have a proc transform to get a single line per fish with prey turned into columns.
EX:
Loc Fishid Beetles Worms Fish



So How do do the first transformation so that the second one works?
Thanks so much for any help.
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Look at using a combination of MERGE with a BY statement and also PROC TRANSPOSE with ID and IDLABEL.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
hello,

if i understood correctly you can use proc format to "label" the prey variable
and then the means procedure to get the output data set:



[pre]

DATA A;
INPUT LOC FISHID PREY AMT;
datalines;
1 1 1 3
1 1 2 30
1 1 3 9
1 1 4 12
1 2 4 6
1 2 6 1
;

proc format;
value name
1='beetles'
2-3='Worms'
4-11='fish';
run;

proc means data=a noprint nway;
class loc fishid prey;
var amt;
output out=a1 (drop=_type_) sum=;
format prey name.;
run;

[/pre]

Marius

SAS Innovate 2025: Register Now

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!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 769 views
  • 0 likes
  • 3 in conversation