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

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
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

1 REPLY 1
Astounding
PROC Star

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.

CFC_SAS_Communities_400x225.jpgCFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 5505 views
  • 0 likes
  • 2 in conversation