Reputation: 209
Say, for example, I have the following data
Dataset name: TheTable
Name Age Height
Peter 21 1.6
Alexa 19 1.8
Rob 23 1.3
I want to get the largest age and height, and store them in the table as follows
Dataset name: TheTableWithMax
Name Age Height MaxAge maxHeight
Peter 21 1.6 23 1.8
Alexa 19 1.8 23 1.8
Rob 23 1.3 23 1.8
The reason for this is that I have to draw a comparison between each variable and the maximum of that variable. How can I go about doing that in SAS?
I have thought of doing the following in order to obtain the max of, say, the Age column (the same process will be done for the Height column)
proc sort data = TheTable (obs=1) out=MaxAge (keep = Age);
by descending Age;
run;
However, I am not sure how I will be able to merge that back with the original TheTable to get TheTablewithMax.
Any assistance will be much appreciated.
Upvotes: 1
Views: 119
Reputation: 1792
This is very easily done with proc sql
and summary functions, in your case max()
:
proc sql;
create table TheTableWithMax as
select *
,max(age) as MaxAge
,max(height) as MaxHeight
from TheTable
;
quit;
Upvotes: 1