BookmarkSubscribeRSS Feed
Khaladdin
Quartz | Level 8

I have a question and want to ask question by using example. My data-set is:

Group Value
1         10
1         8
1        12
2        13
2        11
2        7
I want to add two columns to this data-set. First column should consist of maximum value of second column by group. Second column should consist of minimum value of second column by group. So, the result should be look:

Group Value Max Min
1          10     12   8
1          8       12   8
1         12      12   8
2         13      13   7
2        11       13   7
2         7        13   7

12 - because there are 3 numbers (10,8,12) in group number 1 and 12 is maximum among these values.
13 - because there are 3 numbers (13,11,7) in group number 2 and 13 is maximum among these values.
8 - because there are 3 numbers (10,8,12) in group number 1 and 8 is minimum among these values.
7 - because there are 3 numbers (13,11,7) in group number 2 and 7 is minimum among these values.
I hope, i can explain it..
Many thanks in advance.

1 REPLY 1
collinelliot
Barite | Level 11

You can get what you want easily with SQL: 

 

proc sql;
    CREATE TABLE want AS
    SELECT *, 
                  min(value) AS min
                  max(value) AS max
    FROM have
    GROUP BY group;
quit;

 

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
  • 1 reply
  • 843 views
  • 0 likes
  • 2 in conversation