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.

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
  • 4325 views
  • 0 likes
  • 2 in conversation