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 Chriss Miller 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
Joined
Sep 11, 2007
Messages
6
Location
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
 
Thank you, Klaz! It works!

Also, I did not know that I could use proc sql to make a macro variable.


proc sql;
select mean(rhin_age)
into: meanage
from orcl.pat_survey1
where rhin_age is not null;
quit;
%put The mean age is: &meanage;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top