BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9

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   

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

You could rather use PROC SUMMARY

 


proc summary data=have nway;
class id;
var pr;
output out=want min= max=/autoname;
run;

View solution in original post

3 REPLIES 3
ed_sas_member
Meteorite | Level 14

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;
novinosrin
Tourmaline | Level 20

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 🙂

novinosrin
Tourmaline | Level 20

You could rather use PROC SUMMARY

 


proc summary data=have nway;
class id;
var pr;
output out=want min= max=/autoname;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1276 views
  • 3 likes
  • 3 in conversation