Solved
Contributor
Posts: 23

# proc means - creating a new column/ variable

[ Edited ]
` `

Question 1 --In i my data i have the columns - probability and Budget.

I want to group the data by probability and get sum of budget = Total budget for each probability level.

I also want a variable named foretasted Budget which which has product of total budget and probability

how do i get this with proc means.?

My half written code-

``````proc means data = c1.od noprint nonobs;
var  Total_Media_Value ;
class _probability___/ descending;
output out=data (drop = _TYPE_ _FREQ_)
sum = Total_Budget
n= num_of_optys;
run;``````

Question 2-- in the output i am getting a row which gives me total of columns. I want to give  that row a name - Total , how do i do that?

eg- my result looks like this -

probability  total budget  num

``````1	.	3200531	361
2	100	68100	7
3	90	56000	4
4	70	23200	8
5	50	156500	18
6	30	112000	5
7	10	2784731	319``````

i want the first row at the end and have it named total

Accepted Solutions
Solution
‎12-28-2017 12:45 PM
Super User
Posts: 6,543

## Re: proc means - creating a new column/ variable

Since you re-posted Question 2 separately, I'll give you an answer to just Question 1 here.

You're asking to calculate a new variable, and add it to an existing data set.  PROC MEANS won't do that, but a DATA step can do that easily.  For example:

data want;

set data;

forecasted_budget = total_budget * _probability___ ;

run;

It's not clear if you want that as the result, or if you should be dividing by 100.  But the formula is up to you.

All Replies
Solution
‎12-28-2017 12:45 PM
Super User
Posts: 6,543

## Re: proc means - creating a new column/ variable

Since you re-posted Question 2 separately, I'll give you an answer to just Question 1 here.

You're asking to calculate a new variable, and add it to an existing data set.  PROC MEANS won't do that, but a DATA step can do that easily.  For example:

data want;

set data;

forecasted_budget = total_budget * _probability___ ;

run;

It's not clear if you want that as the result, or if you should be dividing by 100.  But the formula is up to you.

☑ This topic is solved.