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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1314 views
  • 3 likes
  • 3 in conversation