Super User

## Re: Quantiles and Sum of Variables...

Art

Really?

I do not know to say what. Maybe Op should post some sample data and output he want to illustrate what exactly he want.

BTW. You still did not go to sleep? Respect!

Ksharp

Calcite | Level 5

## Re: Quantiles and Sum of Variables...

Thank you all for your assistance!

@Ksharp: Since I'm not familiar with macro I cannot check wether your code does the same...

The problem with Art297's suggested code is that it does not seem to work when the variables have more then just one observation. Summing up the observations for each variable would not solve the problem cause I need them separated.

Opal | Level 21

## Re: Quantiles and Sum of Variables...

Mark,

When you say "when the variables have more than just one observation" do you mean "when there is more than just one record"?

My understanding is that you have 2 or more records, with each record having 5000 variables that you want to sum (within each record) for each set of 500 variables.

Obviously, I am misunderstanding something!

Calcite | Level 5

## Re: Quantiles and Sum of Variables...

Sorry for confusing you...

When I'm speaking of observations I mean records.... And yes the number of records is greater than two. Maybe there has been a slight mixup....

Please excuse if I'm a bit slow in the mind. But using your code on the entire records leads to an error. Do I have to peform the code on every record separately?

Opal | Level 21

## Re: Quantiles and Sum of Variables...

Mark,

There was a line missing from my code.  k has to be initialized at the beginning of each record.  Try it with the following:

data want (drop=a: y:);

set have;

/*  assign all 5000 variables to the array a*/

array a(5000) a1-a5000;

/*initialize 2 additional arrays to represent x1 to*/

/*x50 .. the variables that will contain the sums and*/

/*y1 to y100 .. the variables that will temporarily*/

/*contain the values from each set of 100 variables*/

array x(50);

array y(100);

k=0;

/*loop through the variables 100 at a time*/

do i=1 to 4901 by 100;

/*fill the array y with each set of 100 variables*/

do j=0 to 99;

y(j+1)=a(i+j);

end;

/*calculate the desired sum*/

k+1;

x(k)=sum(of y:);

/*move onto the next set of 100 variables*/

end;

run;

Calcite | Level 5

## Re: Quantiles and Sum of Variables...

Works like a charm.... Thank you so much!!!!

Discussion stats
• 20 replies
• 3464 views
• 7 likes
• 5 in conversation