Hi! I have three variables, fev11, fev12, and fev13 and I need to create a new variable called fev_max that scans those three variables and finds that maximum value of the three to fill in fev_max. I need to do this by participant ID (PID). What is the best way to create this new variables. I have only ever done this using R and am not sure how to do it in SAS. Thank you in advance for any help you can give me. es
How about using:
fev_max=LARGEST(1, fev11, fev12, fev13);
or
fev_max=MAX(fev11, fev12, fev13);
That worked, thank you! I have never used the MAX or LARGEST functions in SAS so I did not know they existed! Thank you for your help!
A really helpful book to get as you build your SAS library is:
"SAS Functions by Example" By Ron Cody.
Great functions and their usage in this book!
Hi Robby,
I like your original photo. Why did you make the change?
HA! - I was just sitting around, had a few minutes on my hands and thought "why not change my picture!"
Thank you for the book suggestion, I will look into purchasing it. Thank you everyone again for the code. These forums are a great place for people like me who still have a lot to learn about SAS and I appreciate being able to come here to get help!
Can a participant have more than one record, ie more than one line in the dataset?
data have;
input id v1-v3;
cards;
1 20 21 19
1 30 32 39
2 15 18 13
;
data temp;
set have;
max=largest(1,of v1-v3);
proc sort;
by id descending max;
data want(drop=max);
retain fev_max;
set temp;
by id;
fev_max=ifn(first.id=1,max,fev_max);
proc print;
run;
Obs fev_max id v1 v2 v3
1 39 1 30 32 39
2 39 1 20 21 19
3 18 2 15 18 13
hi ... here's a variation on Linlin's idea (where there might be multiple observations with the same ID) ...
data want;
do until (last.id);
set have (in=one) have;
by id;
if one then vmax = max(vmax, of v:);
else output;
end;
run;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.