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


Hi,

I have a file with over 43000 unique rows  which has a variable called model, I would like to get the average of this variable model for every fifth row.

I also have the file number indexed from 1 to 43000 but I am stuggling to get it to average it. I would even appreciate help with how to code every row into the same group by creating a new headin as then I could get the means by selecting unique group.

The file currently looks like;

position     model     n

483_1       0.1234     1

678_1       0.2345     2

876_1       0.1456     3

Thank you! Smiley Happy

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

data have;
do i=1 to 50;
output;end;
run;

data want;
set have;
n=int((i-1)/5)+1;
proc print;run;

View solution in original post

4 REPLIES 4
Linlin
Lapis Lazuli | Level 10

data have;
do i=1 to 50;
output;end;
run;

data want;
set have;
n=int((i-1)/5)+1;
proc print;run;

PGStats
Opal | Level 21

I'm not sure I understand the question fully but would something like this do what you want :

proc means data=MyData(where=(mod(n,5)=0));

var model;

run;

PG

PG
esjackso
Quartz | Level 8

I think we are all getting to the same point ... but here is my version:

data test3;

  set test2;

  if n = 1 then cat = 0;

  group = mod(n,5);

  if group = 1 then cat + 1;

run;

the group variable is basically providing an indicator for every 5th observation. The cat variable is categorizing the group of 5 observations (1-5 cat 1 , 6 - 10 cat2 , etc...).

I wasnt clear if you are average the five observations (average obs 1 through 5, 6 through 10, etc... which would be over 8000 averages) or eliminate all but every 5th obs and average those obs for an outcome of one number.

Anyway .. hope this helps!

EJ

purfield
Calcite | Level 5

Thanks to everyone for their help, that worked perfectly!first time posting in a forum and was great to get such answers!

Thank you! Smiley Happy

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 Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2140 views
  • 6 likes
  • 4 in conversation