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....'

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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