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
dlazer1
Calcite | Level 5

Thank you!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1090 views
  • 0 likes
  • 2 in conversation