BookmarkSubscribeRSS Feed
ndp
Quartz | Level 8 ndp
Quartz | Level 8

wonderful. try this.

data have;
set have;
dt=input(dtc,date7.);
format dt date7.;
year=year(dt);
run;

proc sort data= have;by dt;
run;

data have1;
set have;
by dt;
retain _dt;
_dt=lag(dt);
if _n_=1 then _dt=dt;
day=dt-_dt+1;
mon6=ceil(day/182.5);
mon12=ceil(day/365);
format _dt date7.;
drop id year dtc;
run;

*** overall avg ;
proc sql noprint;
create table avg1 as
select mean(day) as avg1
from have1;
quit;

*** 6 mon avg;
proc sql noprint;
create table _avg6 as
select mon6, mean(day) as _avg6
from have1
group by mon6;
quit;

proc sql noprint;
create table avg6 as
select mean(_avg6) as avg6
from _avg6
;
quit;

*** 12 mon avg;
proc sql noprint;
create table _avg12 as
select mon6, mean(day) as _avg12
from have1
group by mon12;
quit;

proc sql noprint;
create table avg12 as
select mean(_avg12) as avg12
from _avg12
;
quit;

if this works you can add var 'year' in by statements starting with proc sort and instead of 'if _n_=1....' use 'if first.year....'

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 15 replies
  • 3635 views
  • 6 likes
  • 4 in conversation