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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 5376 views
  • 6 likes
  • 4 in conversation