Hello-;
Please can you the code to create a data of max min from longitudinal data. The data is below:
Id PR
1 2
1 3
1 4
1 2
1 1
2 2
2 3
2 3
2 5
Create a Data with max PR
Id PR
1 4
2 5
Data with min PR
Id PR
1 1
2 2
You could rather use PROC SUMMARY
proc summary data=have nway;
class id;
var pr;
output out=want min= max=/autoname;
run;
Hi @desireatem
You can use PROC SQL:
data have;
input Id PR;
datalines;
1 2
1 3
1 4
1 2
1 1
2 2
2 3
2 3
2 5
;
run;
proc sql;
create table have_max as
select Id, max(PR) as PR
from have
group by Id;
run;
proc sql;
create table have_min as
select Id, min(PR) as PR
from have
group by Id;
run;
You could combine into one and have a group label if you like
data have;
input Id PR;
cards;
1 2
1 3
1 4
1 2
1 1
2 2
2 3
2 3
2 5
;
proc sql;
create table combined as
select id,'max' as Max,max(pr) as Max_PR
from have
group by id
union all
select id,'min' as Min, min(pr) as Min_pr
from have
group by id;
quit;
One way to turn @PaigeMiller red is splitting datasets when not needed 🙂
You could rather use PROC SUMMARY
proc summary data=have nway;
class id;
var pr;
output out=want min= max=/autoname;
run;
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.