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!
data have;
do i=1 to 50;
output;end;
run;
data want;
set have;
n=int((i-1)/5)+1;
proc print;run;
data have;
do i=1 to 50;
output;end;
run;
data want;
set have;
n=int((i-1)/5)+1;
proc print;run;
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
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
Thanks to everyone for their help, that worked perfectly!first time posting in a forum and was great to get such answers!
Thank you!
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!
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.