## Maximum value of a numeric variable sorted by patients

Solved
Occasional Contributor
Posts: 15

# Maximum value of a numeric variable sorted by patients

Hi,

I have a dataset sorted by patients; e.g. 2 observations/lines (of data) for patient 1, 4 lines for patient 2 and so on. I have a variable (we call it "LINES") counting the lines for each patient (1, 2, 3, 4 and so on).

I need to create a new variable with data from the the last line for each patient, in other words the highest value of the variable "LINES" (sorted by patients).

How do I create a syntax with "highest value" (it should bed sorted by patients already) of a variable?

/Mette

Accepted Solutions
Solution
‎03-31-2016 03:15 AM
Super User
Posts: 10,270

## Re: Maximum value of a numeric variable sorted by patients

[ Edited ]
``````proc sort data=have;
by patient lines;
run;

data want;
set have;
by patient;
if last.patient;
run;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

All Replies
Super Contributor
Posts: 319

## Re: Maximum value of a numeric variable sorted by patients

Hello,

Instead of describing in words your situation it will be useful to post an example of your data.

It is easier to look at data you have - data you want than reading a description.

Solution
‎03-31-2016 03:15 AM
Super User
Posts: 10,270

## Re: Maximum value of a numeric variable sorted by patients

[ Edited ]
``````proc sort data=have;
by patient lines;
run;

data want;
set have;
by patient;
if last.patient;
run;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 15