BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Catalina1972
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

7 REPLIES 7
Astounding
PROC Star

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?

Catalina1972
Calcite | Level 5

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

ballardw
Super User

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.

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


##- Please type your reply above this line. Simple formatting, no
attachments. -##
Catalina1972
Calcite | Level 5

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

Astounding
PROC Star

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.

Catalina1972
Calcite | Level 5
Thanks
works great!

##- Please type your reply above this line. Simple formatting, no
attachments. -##

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1494 views
  • 0 likes
  • 3 in conversation