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

Hi,

 

What is the best way to output the average X (Earnings/price) per year into the dataset with all my other variables. Here is the previous code I have tried but it is not including the mean EP per year next to each row (I need it to show per observation for my future calculation).

 

Thank you!

 

proc sort data=marketadj1;
by fyear X;
run;

proc means data=marketadj1;
var X;
by fyear;
run;

proc univariate data=marketadj1;
var x;
by fyear;
output mean=mean;
run;

proc print data=marketadj1 (obs=100);
run;

 

proc means data=marketadj1;
467 var X;
468 by fyear;
469 output=mean;
------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

470 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


471 proc univariate data=marketadj1;
472 var x;
473 by fyear;
474 out=meanstate mean n;
---
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
475 run;

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


476 proc univariate data=marketadj1;
477 var x;
478 by fyear;
479 output mean n;
-
73
ERROR 73-322: Expecting an =.
480 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.DATA1 may be incomplete. When this step was stopped there
were 0 observations and 0 variables.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds

 

481
482 proc univariate data=marketadj1;
483 var x;
484 by fyear;
485 output mean;
-
73
ERROR 73-322: Expecting an =.
486 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.DATA2 may be incomplete. When this step was stopped there
were 0 observations and 0 variables.
NOTE: PROCEDURE UNIVARIATE used (Total process time):
real time 0.03 seconds
cpu time 0.00 seconds

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@dlazer1 wrote:

Hi,

 

What is the best way to output the average X (Earnings/price) per year into the dataset with all my other variables. Here is the previous code I have tried but it is not including the mean EP per year next to each row (I need it to show per observation for my future calculation).

 

Thank you!

 

proc sort data=marketadj1;
by fyear X;
run;

proc means data=marketadj1;
var X;
by fyear;
run;


If I am understanding the problem properly, you want the original data set, but with an additional column that contains the mean of X. Is that correct? Can you confirm?

 

Try this:

proc summary data=marketadj1 nway;
    class fyear;
    var x;
    output out=_stats_ mean=meanX;
run;
proc sort data=marketadj1;
    by fyear;
run;
data want;
    merge marketadj1 _stats_;
    by fyear;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

@dlazer1 wrote:

Hi,

 

What is the best way to output the average X (Earnings/price) per year into the dataset with all my other variables. Here is the previous code I have tried but it is not including the mean EP per year next to each row (I need it to show per observation for my future calculation).

 

Thank you!

 

proc sort data=marketadj1;
by fyear X;
run;

proc means data=marketadj1;
var X;
by fyear;
run;


If I am understanding the problem properly, you want the original data set, but with an additional column that contains the mean of X. Is that correct? Can you confirm?

 

Try this:

proc summary data=marketadj1 nway;
    class fyear;
    var x;
    output out=_stats_ mean=meanX;
run;
proc sort data=marketadj1;
    by fyear;
run;
data want;
    merge marketadj1 _stats_;
    by fyear;
run;
--
Paige Miller

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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