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 180322: 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 180322: 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 73322: 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 73322: 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
@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;
@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;
Thank you!
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.