data try_data;
input V1 V2 V3;
datalines;
3 1 1
2 3 2
1 1 2
0 2 3
4 0 4
0 0 0
1 3 2 ;
run;
Hello,
I have 3 numeric variables. I would like to create a new variable which retrieves each time, by observation, the greatest value between my 3 numerical variables.
For example:
V1=3 V2=1 V3=1 then New_V=3
V1=2 V2=3 V3=2 then New_V=3
V1=1 V2=1 V3=2 then New_V=2
V1=0 V2=2 V3=3 then New_V=3
V1=4 V2=0 V3=4 then New_V=4
V1=0 V2=0 V3=0 then New_V=0
V1=1 V2=3 V2=2 then New_V=3
Thank you in advance for your assistance.
Gick
Use the max function.
Use the max function.
First item, the semicolon that ends a datalines block must be on its own line.
data try_data; input V1 V2 V3; new_v = max(v1,v2,v3); datalines; 3 1 1 2 3 2 1 1 2 0 2 3 4 0 4 0 0 0 1 3 2 ; run;
There a many functions for statistics of variables in a single record in SAS: N, NMISS, MAX, MIN, MEAN, MEDIAN, IQR, STD and more.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.