DATA Step, Macro, Functions and more

Maximum value of a numeric variable sorted by patients

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

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: 6,928

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

View solution in original post


All Replies
Super Contributor
Posts: 305

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: 6,928

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
Occasional Contributor
Posts: 15

Re: Maximum value of a numeric variable sorted by patients

Thanks a lot KurtBremser. It was exactly the commando I needed. Smiley Happy

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 264 views
  • 4 likes
  • 3 in conversation