## Creating a column based on max values of row

Solved
Occasional Contributor
Posts: 5

# Creating a column based on max values of row

Hi all,

I need help with calculating the max of a column for every 10 rows.  Here is the example of data

I am stuck with this, I appreciate any help

Thanks

Data Group
65.36574767 5
69.07862909 2
63.25081767 8
69.07863052 1
66.88025195 3
64.26943767 9
64.62144481 6
63.38701767 7
63.63735481 4
63.48772767 10
65.3728169 5
69.85877404 2
65.26442976 8
66.87676547 1
67.33332404 3
64.85199404 9
65.58766547 6
64.8385669 7
64.3282969 4
63.91490118 10

Accepted Solutions
Solution
‎11-29-2016 01:41 PM
Super User
Posts: 5,717

## Re: Creating a column based on max values of row

OK, here's one approach:

data want;

do _n_=1 to 10;

set have;

minHeight = min(Height, minHeight);

maxHeight = max(Height, maxHeight);

end;

do _n_=1 to 10;

set have;

output;

minHeight=.;

maxHeight=.;

end;

run;

The two lines after the OUTPUT statement are optional.  From your description, you only want those variables on the first observation for a group.  You could try omitting those two statements, as an experiment.

All Replies
Super User
Posts: 5,717

## Re: Creating a column based on max values of row

What do you want as the output?  A report (what should it look like)?  A SAS data set with the same number of observations, but MAX_10 attached as a third variable?  A SAS data set with one observation for each original 10 observations?

Are you 100% sure that you always have all 10 GROUP values every time?

Occasional Contributor
Posts: 5

## Re: Creating a column based on max values of row

Thank you, I need to create another column in the initial data set that will calculate min/max and some other computations.  I will always have 10 group values as I am meassuring 10  same locations each time

Catalina

Super User
Posts: 11,793

## Re: Creating a column based on max values of row

Please show what the result for your example data would look like as there are several ways to interpret your request and some are quite a bit more obnoxious to accomplish then others. Also, depending on the exact "other computations" the approach that works for Min and Max may not work.

Occasional Contributor
Posts: 5

## Re: Creating a column based on max values of row

Here is the data. I have Max-Min but I need columns for Max and Min
individually. The tools spits Max-Min...
Thanks

attachments. -##
Occasional Contributor
Posts: 5

## Re: Creating a column based on max values of row

here is the data set

Height Average Max-Min Pillar
65.36574767 65.30570595 5.827812857 5
69.07862909 2
63.25081767 8
69.07863052 1
66.88025195 3
64.26943767 9
64.62144481 6
63.38701767 7
63.63735481 4
63.48772767 10
65.3728169 65.82275347 5.943872857 5
69.85877404 2
65.26442976 8
66.87676547 1
67.33332404 3
64.85199404 9
65.58766547 6
64.8385669 7
64.3282969 4
63.91490118 10
64.81566355 66.16816555 7.866974286 5
71.0156307 2
63.81814355 8
71.55371498 1
68.77600784 3
65.16479498 9
65.11012355 6
63.82965355 7
63.91118213 4
63.6867407 10
64.82539697 65.94098597 9.509042857 5
71.13182554 2
64.52901554 8
72.4554584 1
68.01074125 3
64.08588697 9
64.78415125 6
63.24279125 7
62.94641554 4
63.39817697 10
65.77032324 66.77302331 10.25718357 5
71.78037895 2
64.82555895 8
74.40845824 1
67.35196895 3
65.42502895 9
65.48257895 6
64.24718895 7
64.15127467 4
64.28747324 10
65.32768603 66.08724017 8.084702857 5
70.31432317 2
64.94306746 8
71.55355031 1
67.05512174 3
65.08406174 9
63.77385746 6
63.46884746 7
64.56324317 4
64.78864317 10

Solution
‎11-29-2016 01:41 PM
Super User
Posts: 5,717

## Re: Creating a column based on max values of row

OK, here's one approach:

data want;

do _n_=1 to 10;

set have;

minHeight = min(Height, minHeight);

maxHeight = max(Height, maxHeight);

end;

do _n_=1 to 10;

set have;

output;

minHeight=.;

maxHeight=.;

end;

run;

The two lines after the OUTPUT statement are optional.  From your description, you only want those variables on the first observation for a group.  You could try omitting those two statements, as an experiment.

Occasional Contributor
Posts: 5

Thanks
works great!