BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasphd
Lapis Lazuli | Level 10

Hi

I want to calculate a mean for a specific day for example here 13-01-2020 using observation 02-01-2020 and 06-01-2020

 

 

 

 

data ind;
input gvkey datadate : yymmdd10. TRT1M;
format date yymmdd10.;
cards;


1 2020-01-02 -1.35
1 2020-01-03 -1.48
1 2020-01-06 2.40
1 2020-01-07 -0.85
1 2020-01-08 -0.24
1 2020-01-09 2.49
1 2020-01-10 1.68
1 2020-01-13 -1.69  
1 2020-01-14 -0.91
1 2020-01-15 -0.93
1 2020-01-16 2.71
1 2020-01-17 -0.05
1 2020-01-20 1.69
1 2020-01-21 -3.64
1 2020-01-22 1.24
1 2020-01-23 -2.05
1 2020-01-24 -2.97
1 2020-01-27 -0.78
1 2020-01-28 3.09


;

 

 

output that I want 

 gvkey datadate TRT1M wantedmean

1 2020-01-02 -1.35
1 2020-01-03 -1.48
1 2020-01-06 2.40
1 2020-01-07 -0.85
1 2020-01-08 -0.24
1 2020-01-09 2.49
1 2020-01-10 1.68
1 2020-01-13 -1.69 -0,14
1 2020-01-14 -0.91
1 2020-01-15 -0.93
1 2020-01-16 2.71
1 2020-01-17 -0.05
1 2020-01-20 1.69
1 2020-01-21 -3.64
1 2020-01-22 1.24
1 2020-01-23 -2.05
1 2020-01-24 -2.97
1 2020-01-27 -0.78
1 2020-01-28 3.09

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc summary data=ind(where=('02JAN2020'd<=datadate<='06JAN2020'd));
	var trt1m;
	output out=_stats_(drop=_:) mean=mean;
run;
data want;
	if _n_=1 then set _stats_;
	set ind;
	if datadate='13JAN2020'd then wantedmean=mean; 
	drop mean;
run;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

I suspect the problem is more general than you stated. To calculate the one mean is very simple, but again I'm guessing the real problem is a larger data set with many means being calculated. In that case, it's not clear why the mean that gets placed next to 2020-01-13 is the mean of 2020-01-02 through 2020-01-06, and what other means gets calculated from what time periods. Can you explain further?

--
Paige Miller
sasphd
Lapis Lazuli | Level 10

here the problem is just to calculate one mean when fixing just one interval

 

PaigeMiller
Diamond | Level 26
proc summary data=ind(where=('02JAN2020'd<=datadate<='06JAN2020'd));
	var trt1m;
	output out=_stats_(drop=_:) mean=mean;
run;
data want;
	if _n_=1 then set _stats_;
	set ind;
	if datadate='13JAN2020'd then wantedmean=mean; 
	drop mean;
run;
--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 582 views
  • 2 likes
  • 2 in conversation