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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.