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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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