BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CharlesFowler72
Obsidian | Level 7

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.

 

SectorVariable AVariable BVariable C
13600 
22003,000 
37200 
450800 
5701,000 
1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

View solution in original post

1 REPLY 1
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 313 views
  • 1 like
  • 2 in conversation