Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use sum of variable in another variable

Status
Not open for further replies.

Starbury

Programmer
Sep 11, 2007
6
US
I have a variable A and variable B and each has 613 observations. Variable C = A/B.

I want to create variable D within the data step that divides sum total of variable A by sum total of variable B. Yes, variable D will be same value for all 613 observations. I cannot use a macro as a constant because variable D is dependent on the sum of variable A and the sum of variable B.

Ultimately, I will create an index so that variable E=C/D

Anyone have advice?

 
You can use PROC SQL for this problem.

See below

Code:
proc sql;
create table test as
select a, b, (a/b) as c, sum(a) as sumA, sum(b) as sumB, sum(a)/sum(b)) as E
from your_dataset;
quit;

Let me know if this works.
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top