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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 647 views
  • 0 likes
  • 2 in conversation