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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.