Hi guys,
struggling with a formula for a new variable. Essentially I want a new variable to be Variable C =Variable A/((Variable B/sum(Variable B))*sum(Variable A).
Seems simple but cant get it to work. If I can get a simple element which gives the column total to use in the formula that would be great.
| Sector | Variable A | Variable B | Variable C |
| 1 | 3 | 600 | |
| 2 | 200 | 3,000 | |
| 3 | 7 | 200 | |
| 4 | 50 | 800 | |
| 5 | 70 | 1,000 |
Hope this what you are expecting
data have;
input Sector VariableA VariableB;
cards;
1 3 600
2 200 3000
3 7 200
4 50 800
5 70 1000
;
proc sql;
create table want as select sector, VariableA, VariableB, (select sum(variableB) from have ) as sumB, (select sum(variableA) from have ) as sumA,
VariableA/((VariableB/(select sum(variableB) from have ))*(select sum(variableA) from have)) as variableC
from have;
quit;
Hope this what you are expecting
data have;
input Sector VariableA VariableB;
cards;
1 3 600
2 200 3000
3 7 200
4 50 800
5 70 1000
;
proc sql;
create table want as select sector, VariableA, VariableB, (select sum(variableB) from have ) as sumB, (select sum(variableA) from have ) as sumA,
VariableA/((VariableB/(select sum(variableB) from have ))*(select sum(variableA) from have)) as variableC
from have;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.